Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill a deadlock in the new thread creation code I've introduced (sometimes, the main...
[simgrid.git] / src / xbt / context.c
index f80d0d812b7aa075079c3a1f749436ef9fcc6264..0cfcb36eff8d77a91defe09a6531e3adaf0b8b00 100644 (file)
@@ -33,8 +33,10 @@ static xbt_context_t current_context = NULL;
 static xbt_context_t init_context = NULL;
 static xbt_swag_t context_to_destroy = NULL;
 static xbt_swag_t context_living = NULL;
+#ifdef CONTEXT_THREADS
 static xbt_mutex_t creation_mutex;
 static xbt_thcond_t creation_cond;
+#endif
 
 static void __context_exit(xbt_context_t context ,int value);
 static void __xbt_context_yield(xbt_context_t context)
@@ -185,13 +187,13 @@ __context_wrapper(void* c) {
         
        DEBUG2("**[%p:%p]** Lock ****",context,(void*)xbt_thread_self());
        xbt_mutex_lock(creation_mutex);
+       xbt_mutex_lock(context->mutex);
        
        DEBUG2("**[%p:%p]** Releasing the creator ****",context,(void*)xbt_thread_self());
        xbt_thcond_signal(creation_cond);
        xbt_mutex_unlock(creation_mutex);
        
        DEBUG2("**[%p:%p]** Going to Jail ****",context,(void*)xbt_thread_self());
-       xbt_mutex_lock(context->mutex);
        xbt_thcond_wait(context->cond, context->mutex);
        
        DEBUG2("**[%p:%p]** Unlocking ****",context,(void*)xbt_thread_self());
@@ -248,8 +250,10 @@ void xbt_context_init(void)
                context_to_destroy = xbt_swag_new(xbt_swag_offset(*current_context,hookup));
                context_living = xbt_swag_new(xbt_swag_offset(*current_context,hookup));
                xbt_swag_insert(init_context, context_living);
+#ifdef CONTEXT_THREADS    
                creation_mutex = xbt_mutex_init();
                creation_cond = xbt_thcond_init();
+#endif    
        }
 }
 
@@ -381,15 +385,18 @@ void xbt_context_exit(void) {
            xbt_context_kill(context);
          }
        }
-       //      xbt_context_kill(init_context);
+       free(init_context->exception);   
+       free(init_context);   
+       init_context = current_context = NULL ;
 
        xbt_context_empty_trash();
        xbt_swag_free(context_to_destroy);
        xbt_swag_free(context_living);
        
-       init_context = current_context = NULL ;
+#ifdef CONTEXT_THREADS    
        xbt_mutex_destroy(creation_mutex);
-       xbt_thcond_destroy(creation_cond);   
+       xbt_thcond_destroy(creation_cond);
+#endif   
 }
 
 /**