Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revalidate the outputs I can test on my machine (build daemons are currently dead)
[simgrid.git] / examples / gras / synchro / philosopher.c
index cc5db31..a19c3c9 100644 (file)
@@ -28,7 +28,7 @@ int *id; /* to pass a pointer to the threads without race condition */
 
 static void pickup(int id, int lunch)  {
    INFO2("Thread %d gets hungry (lunch #%d)",id,lunch);
-   xbt_mutex_lock(mutex);
+   xbt_mutex_acquire(mutex);
    while (state[(id + (philosopher_amount-1))%philosopher_amount] == EATING ||
          state[(id + 1)%philosopher_amount] == EATING) 
      {
@@ -40,17 +40,17 @@ static void pickup(int id, int lunch)  {
               state[(id + 1)%philosopher_amount] == THINKING ,
               "Philosopher %d eats at the same time that one of its neighbors!!!",id);
        
-   xbt_mutex_unlock(mutex);
+   xbt_mutex_release(mutex);
    INFO1("Thread %d eats",id);
 }
 static void putdown(int id)  {
    INFO1("Thread %d is full",id);
-   xbt_mutex_lock(mutex);
+   xbt_mutex_acquire(mutex);
    state[id] = THINKING;
    xbt_cond_signal(forks[(id+(philosopher_amount-1))%philosopher_amount]);
    xbt_cond_signal(forks[(id+1)%philosopher_amount]);
    
-   xbt_mutex_unlock(mutex);
+   xbt_mutex_release(mutex);
    INFO1("Thread %d thinks",id);
 }
 
@@ -75,14 +75,14 @@ static void philo_thread(void *arg) {
       gras_os_sleep(id / 100.0);
    }
    
-   xbt_mutex_lock(mut_end);
+   xbt_mutex_acquire(mut_end);
    running_threads--;
    xbt_cond_signal(cond_end);
-   xbt_mutex_unlock(mut_end);
+   xbt_mutex_release(mut_end);
 
    /* Enter an endless loop to test the killing facilities */
    INFO1("Thread %d tries to enter the dead-end; hopefully, the master will cancel it",id);
-   xbt_mutex_lock(dead_end);
+   xbt_mutex_acquire(dead_end);
    INFO1("Oops, thread %d reached the dead-end. Cancelation failed",id);
 }
 
@@ -113,9 +113,9 @@ int philosopher (int argc,char *argv[]) {
   cond_end = xbt_cond_init();
   mut_end = xbt_mutex_init();
   dead_end = xbt_mutex_init();
-  xbt_mutex_lock(dead_end);
+  xbt_mutex_acquire(dead_end);
   
-  INFO0("Spawn the threads");
+  INFO2("Spawn the %d threads (%d lunches scheduled)", philosopher_amount, lunch_amount);
   /* spawn threads */
   for (i=0; i<philosopher_amount; i++) {
      char *name = bprintf("thread %d",i);
@@ -124,10 +124,10 @@ int philosopher (int argc,char *argv[]) {
   }
   
   /* wait for them */
-  xbt_mutex_lock(mut_end);
+  xbt_mutex_acquire(mut_end);
   while (running_threads) 
      xbt_cond_wait(cond_end,mut_end);
-  xbt_mutex_unlock(mut_end);
+  xbt_mutex_release(mut_end);
        
   INFO0("Cancel all childs");
   /* nuke them threads */
@@ -135,7 +135,7 @@ int philosopher (int argc,char *argv[]) {
     xbt_thread_cancel(philosophers[i]);
   }
 
-  xbt_mutex_unlock(dead_end);
+  xbt_mutex_release(dead_end);
   gras_exit();
   return 0;
 }