Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Go for a thread_cancel instead of a thread_destroy since every documentation says...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 11 Jul 2007 17:50:08 +0000 (17:50 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 11 Jul 2007 17:50:08 +0000 (17:50 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3741 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/xbt/synchro.h
src/xbt/xbt_os_thread.c
src/xbt/xbt_rl_synchro.c
src/xbt/xbt_sg_synchro.c

index 84bdb79..92e8d3a 100644 (file)
@@ -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 */
index b023fe8..2dc4aa2 100644 (file)
@@ -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_ {
index 9c6bde4..dfb439a 100644 (file)
@@ -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) */
index ee00c07..bf28586 100644 (file)
@@ -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) {