X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/19bdb25835da6ee353675dfb995cf9ca886361b2..55053de21d932fb0cc93eec52ec22ebc38ae936f:/src/xbt/context.c diff --git a/src/xbt/context.c b/src/xbt/context.c index d62813704e..fce1e64c3c 100644 --- a/src/xbt/context.c +++ b/src/xbt/context.c @@ -44,11 +44,17 @@ static void __xbt_context_yield(xbt_context_t context) #ifdef USE_PTHREADS if (context) { xbt_context_t self = current_context; + DEBUG0("**** Locking ****"); pthread_mutex_lock(&(context->mutex)); + DEBUG0("**** Updating current_context ****"); current_context = context; + DEBUG0("**** Releasing the prisonner ****"); pthread_cond_signal(&(context->cond)); + DEBUG0("**** Going to jail ****"); pthread_cond_wait(&(context->cond), &(context->mutex)); + DEBUG0("**** Unlocking ****"); pthread_mutex_unlock(&(context->mutex)); + DEBUG0("**** Updating current_context ****"); current_context = self; } #else @@ -102,6 +108,8 @@ static void *__context_wrapper(void *c) int i; #ifdef USE_PTHREADS + pthread_mutex_lock(&(context->mutex)); + pthread_cond_signal(&(context->cond)); pthread_cond_wait(&(context->cond), &(context->mutex)); pthread_mutex_unlock(&(context->mutex)); #endif @@ -167,11 +175,12 @@ void xbt_context_empty_trash(void) void xbt_context_start(xbt_context_t context) { #ifdef USE_PTHREADS - pthread_mutex_lock(&(context->mutex)); - /* Launch the thread */ + pthread_mutex_lock(&(context->mutex)); xbt_assert0(!pthread_create(context->thread, NULL, __context_wrapper, context), "Unable to create a thread."); + pthread_cond_wait(&(context->cond), &(context->mutex)); + pthread_mutex_unlock(&(context->mutex)); #else makecontext (&(context->uc), (void (*) (void)) __context_wrapper, 1, context);