From 7166ae6c85f79709c2d6dedb68b0c39af3222857 Mon Sep 17 00:00:00 2001 From: mquinson Date: Wed, 11 Jul 2007 17:50:08 +0000 Subject: [PATCH] Go for a thread_cancel instead of a thread_destroy since every documentation says that it is the way to go git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3741 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/xbt/synchro.h | 4 ++-- src/xbt/xbt_os_thread.c | 7 ++++++- src/xbt/xbt_rl_synchro.c | 3 +++ src/xbt/xbt_sg_synchro.c | 6 ++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/xbt/synchro.h b/include/xbt/synchro.h index 84bdb79798..92e8d3ae9f 100644 --- a/include/xbt/synchro.h +++ b/include/xbt/synchro.h @@ -37,8 +37,8 @@ SG_BEGIN_DECL() XBT_PUBLIC(xbt_thread_t) xbt_thread_self(void); /* xbt_thread_join frees the joined thread (ie the XBT wrapper around it, the OS frees the rest) */ XBT_PUBLIC(void) xbt_thread_join(xbt_thread_t thread); - /* Brutally ends the life of the poor victim */ - XBT_PUBLIC(void) xbt_thread_destroy(xbt_thread_t thread); + /* Ends the life of the poor victim (not always working if it's computing, but working if it's blocked in the OS) */ + XBT_PUBLIC(void) xbt_thread_cancel(xbt_thread_t thread); /* suicide */ XBT_PUBLIC(void) xbt_thread_exit(void); /* current thread pass control to any possible thread wanting it */ diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index b023fe80fc..2dc4aa24d3 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -59,7 +59,6 @@ static void * wrapper_start_routine(void *s) { THROW0(system_error,errcode,"pthread_setspecific failed for xbt_self_thread_key"); return t->start_routine(t->param); } - xbt_os_thread_t xbt_os_thread_create(pvoid_f_pvoid_t start_routine, void* param) { int errcode; @@ -98,6 +97,9 @@ xbt_os_thread_t xbt_os_thread_self(void) { void xbt_os_thread_yield(void) { sched_yield(); } +void xbt_os_thread_cancel(xbt_os_thread_t t) { + pthread_cancel(t->t); +} /****** mutex related functions ******/ typedef struct xbt_os_mutex_ { /* KEEP IT IN SYNC WITH xbt_thread.c */ @@ -301,6 +303,9 @@ void *xbt_os_thread_getparam(void) { void xbt_os_thread_yield(void) { Sleep(0); } +void xbt_os_thread_cancel(xbt_os_thread_t t) { + THROW_UNIMPLEMENTED; +} /****** mutex related functions ******/ typedef struct xbt_os_mutex_ { diff --git a/src/xbt/xbt_rl_synchro.c b/src/xbt/xbt_rl_synchro.c index 9c6bde4530..dfb439a1ee 100644 --- a/src/xbt/xbt_rl_synchro.c +++ b/src/xbt/xbt_rl_synchro.c @@ -60,6 +60,9 @@ xbt_thread_t xbt_thread_self(void) { void xbt_thread_yield(void) { xbt_os_thread_yield(); } +void xbt_thread_cancel(xbt_thread_t t) { + xbt_os_thread_cancel(t->os_thread); +} /****** mutex related functions ******/ struct xbt_mutex_ { /* KEEP IT IN SYNC WITH OS IMPLEMENTATION (both win and lin) */ diff --git a/src/xbt/xbt_sg_synchro.c b/src/xbt/xbt_sg_synchro.c index ee00c07ba3..bf28586441 100644 --- a/src/xbt/xbt_sg_synchro.c +++ b/src/xbt/xbt_sg_synchro.c @@ -49,13 +49,15 @@ xbt_thread_join(xbt_thread_t thread) { } void -xbt_thread_destroy(xbt_thread_t thread) { +xbt_thread_cancel(xbt_thread_t thread) { SIMIX_process_kill(thread->s_process); free(thread); } void xbt_thread_exit() { - xbt_thread_destroy(xbt_thread_self()); + xbt_thread_t me=SIMIX_process_get_data(SIMIX_process_self()); + SIMIX_process_kill(me->s_process); + free(me); } xbt_thread_t xbt_thread_self(void) { -- 2.20.1