This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: threads and signals


Christopher Faylor wrote:
On Mon, May 12, 2003 at 04:40:30PM +0200, Thomas Pfaff wrote:

P.S. : It might be that i am too blind to see but it seems that errno is
not thread specific. This will be the No. 1 topic to fix.

Why do you think it isn't thread specific?

Run the attached testcase. errno is stored global in _impure_ptr and is not thread specific.

Thomas
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>

#include <pthread.h>
#include <sys/signal.h>
#include <sys/errno.h>
#include <unistd.h>
#include <string.h>

#define NUMTHREADS 5

void *threadfunc(void *parm)
{
  pthread_t self = pthread_self();

  printf ("Thread %p entered\n", self);
  fflush (stdout);

  errno = (int) parm;
  sleep (2);

  printf ("Thread %d: errno %d @ %p, should be %d\n", (int) parm, errno, &errno, (int) parm);
  fflush (stdout);

  return NULL;
}

int main(void)
{
  int i;
  pthread_t threads[NUMTHREADS];

  errno = 0;

  printf ("Enter Testcase - %p\n", pthread_self ());
  fflush (stdout);

  for(i=0; i<NUMTHREADS; ++i)
    pthread_create (&threads[i], NULL, threadfunc, (void *) i +1);

  for(i=0; i<NUMTHREADS; ++i)
    pthread_join (threads[i], NULL);

  printf ("main: errno %d @ %p, should be 0\n", errno, &errno);
  fflush (stdout);

  return 0;
}
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]