Index: thread.h =================================================================== RCS file: /cvs/src/src/winsup/cygwin/thread.h,v retrieving revision 1.16 diff -u -p -r1.16 thread.h --- thread.h 2001/04/13 15:28:20 1.16 +++ thread.h 2001/04/13 23:50:14 @@ -333,6 +333,7 @@ public: /* we may get 0 for the Tls index.. grrr */ int indexallocated; int concurrency; + long int threadcount; // Used for main thread data, and sigproc thread struct __reent_t reents; @@ -346,7 +347,7 @@ public: void Init (int); - MTinterface ():reent_index (0), indexallocated (0) + MTinterface ():reent_index (0), indexallocated (0), threadcount (1) { pthread_prepare = NULL; pthread_child = NULL; Index: thread.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/thread.cc,v retrieving revision 1.23 diff -u -p -r1.23 thread.cc --- thread.cc 2001/04/13 15:28:20 1.23 +++ thread.cc 2001/04/13 23:50:16 @@ -291,6 +291,7 @@ MTinterface::Init (int forked) } concurrency = 0; + threadcount = 1; /* 1 current thread when Init occurs.*/ if (forked) return; @@ -664,6 +665,7 @@ __pthread_create (pthread_t * thread, co *thread = NULL; return EAGAIN; } + InterlockedIncrement(&MT_INTERFACE->threadcount); return 0; } @@ -1214,10 +1216,12 @@ __pthread_exit (void *value_ptr) class pthread *thread = __pthread_self (); MT_INTERFACE->destructors.IterateNull (); -// FIXME: run the destructors of thread_key items here thread->return_ptr = value_ptr; - ExitThread (0); + if (InterlockedDecrement(&MT_INTERFACE->threadcount) == 0) + exit (0); + else + ExitThread (0); } int