Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Stupid me !
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 28 Feb 2005 22:40:06 +0000 (22:40 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 28 Feb 2005 22:40:06 +0000 (22:40 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1119 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/xbt/context.c

index f5af18b..fce1e64 100644 (file)
@@ -44,11 +44,17 @@ static void __xbt_context_yield(xbt_context_t context)
 #ifdef USE_PTHREADS
   if (context) {
     xbt_context_t self = current_context;
 #ifdef USE_PTHREADS
   if (context) {
     xbt_context_t self = current_context;
+    DEBUG0("**** Locking ****");
     pthread_mutex_lock(&(context->mutex));
     pthread_mutex_lock(&(context->mutex));
+    DEBUG0("**** Updating current_context ****");
     current_context = context;
     current_context = context;
+    DEBUG0("**** Releasing the prisonner ****");
     pthread_cond_signal(&(context->cond));
     pthread_cond_signal(&(context->cond));
+    DEBUG0("**** Going to jail ****");
     pthread_cond_wait(&(context->cond), &(context->mutex));
     pthread_cond_wait(&(context->cond), &(context->mutex));
+    DEBUG0("**** Unlocking ****");
     pthread_mutex_unlock(&(context->mutex));
     pthread_mutex_unlock(&(context->mutex));
+    DEBUG0("**** Updating current_context ****");
     current_context = self;
   }
 #else
     current_context = self;
   }
 #else
@@ -103,6 +109,7 @@ static void *__context_wrapper(void *c)
 
 #ifdef USE_PTHREADS
   pthread_mutex_lock(&(context->mutex));
 
 #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
   pthread_cond_wait(&(context->cond), &(context->mutex));
   pthread_mutex_unlock(&(context->mutex));
 #endif
@@ -169,8 +176,11 @@ void xbt_context_start(xbt_context_t context)
 {
 #ifdef USE_PTHREADS
   /* Launch the thread */
 {
 #ifdef USE_PTHREADS
   /* Launch the thread */
+  pthread_mutex_lock(&(context->mutex));
   xbt_assert0(!pthread_create(context->thread, NULL, __context_wrapper, context),
              "Unable to create a thread.");
   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);
 #else
   makecontext (&(context->uc), (void (*) (void)) __context_wrapper,
               1, context);