This is the mail archive of the pthreads-win32@sourceware.cygnus.com mailing list for the pthreas-win32 project.


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

Re: C++ cleanup handler execution



Sorry, in my previous email my test file got garbled.  
My fault.

--kevin

Here's the test file:


// this is a C++ program

#ifdef __unix
#include <unistd.h>
#else

#endif
#include <pthread.h>
#include "stdio.h"

void *canceledRoutine(void *), *anotherRoutine(void *);

pthread_t canceledThread, anotherThread;

int
main(int argc, char *argv[])
{
  int i = 0;
  pthread_attr_t tattr;
  pthread_attr_init(&tattr);
  pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);

  for (i=0; i<10000; i++) {
    pthread_create(&canceledThread, &tattr, canceledRoutine, (void *)i);
    pthread_create(&anotherThread, 0, anotherRoutine, (void *)i);

    pthread_join(anotherThread, 0);
  }

  sleep(5);
}

void cancelCleanup(void *arg)
{
  int i = (int)arg;

  fprintf(stderr, "%d -- Hey, I've been canceled!\n", i);
}


void *
canceledRoutine(void *arg)
{
  int i = (int)arg;

  pthread_cleanup_push(cancelCleanup, i);

  while(1) {
    // sleep() is defined to be a cancelation point
    sleep(1);
  }
  
  pthread_cleanup_pop(0);
  
  return 0;
}

void *
anotherRoutine(void *arg)
{
  int i = (int)arg;

  pthread_cancel(canceledThread);
  
  return 0;
}


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