diff options
Diffstat (limited to 'exit.c')
-rw-r--r-- | exit.c | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -15,6 +15,30 @@ pthread_exit(void * value) strict POSIX conformance. We must add code here later which deals with executing cleanup handlers and such. For now, the following is mostly correct: */ + int t; - ExitThread((DWORD) value); + t = _pthread_getthreadindex(pthread_self()); + handler = _pthread_threads_table[t]->cleanupstack->first; + + /* Run all the cleanup handlers */ + while (handler != NULL) { + void (* func)(void *); + void * arg; + _pthread_cleanup_node_t * next; + + func = handler->routine; + arg = handler->arg; + _pthread_threads_table[t]->cleanupstack->first = next = handler->next; + free(handler); + (void) func(arg); + } + + /* CRITICAL SECTION */ + pthread_mutex_lock(&_pthread_count_mutex); + free(_pthread_threads_table[t]->attr); + _pthread_threads_table[t]->thread = NULL; + pthread_mutex_unlock(&_pthread_count_mutex); + /* END CRITICAL SECTION */ + + _endthreadex((DWORD) value); } |