X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1367acede3ffaa7fb76cb2a7bf6955575ff466ab..d6ae7b948dffd7f9268106a86f9de21d7d0a3621:/src/xbt/xbt_os_thread.c diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index 00e5c55938..46196d6be7 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -103,6 +103,13 @@ void xbt_os_thread_mod_exit(void) { // if ((errcode=pthread_key_delete(xbt_self_thread_key))) // THROW0(system_error,errcode,"pthread_key_delete failed for xbt_self_thread_key"); + free(main_thread->exception); + free(main_thread); + main_thread = NULL; + thread_mod_inited=0; +#ifndef HAVE_SEM_WAIT + xbt_os_mutex_destroy(next_sem_ID_lock); +#endif } static void * wrapper_start_routine(void *s) { @@ -155,6 +162,9 @@ xbt_os_thread_join(xbt_os_thread_t thread,void ** thread_return) { if (thread->exception) free(thread->exception); + if (thread->name) + free(thread->name); + if (thread == main_thread) /* just killed main thread */ main_thread = NULL; @@ -557,14 +567,15 @@ void xbt_os_thread_mod_exit(void) { static DWORD WINAPI wrapper_start_routine(void *s) { xbt_os_thread_t t = (xbt_os_thread_t)s; - void* rv; + DWORD* rv; if(!TlsSetValue(xbt_self_thread_key,t)) THROW0(system_error,(int)GetLastError(),"TlsSetValue of data describing the created thread failed"); - rv = (*(t->start_routine))(t->param); + rv = (DWORD*)((t->start_routine)(t->param)); - return *((DWORD*)rv); + return rv ? *rv : 0; + } @@ -611,7 +622,10 @@ xbt_os_thread_join(xbt_os_thread_t thread,void ** thread_return) { } CloseHandle(thread->handle); - free(thread->name); + + if(thread->name) + free(thread->name); + free(thread); } @@ -636,7 +650,8 @@ void xbt_os_thread_yield(void) { Sleep(0); } void xbt_os_thread_cancel(xbt_os_thread_t t) { - THROW_UNIMPLEMENTED; + if(!TerminateThread(t->handle,0)) + THROW0(system_error,(int)GetLastError(), "TerminateThread failed"); } /****** mutex related functions ******/