Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
name the threads
[simgrid.git] / examples / gras / synchro / philosopher.c
index 3ce27ca..5095a5e 100644 (file)
@@ -70,9 +70,9 @@ static void philo_thread(void *arg) {
    
    for (i=0; i<lunch_amount; i++) {
       pickup(id,i);
-      gras_os_sleep(id / 10.0); /* each philosopher sleeps and eat a time related to its ID */
+      gras_os_sleep(id / 100.0); /* each philosopher sleeps and eat a time related to its ID */
       putdown(id);
-      gras_os_sleep(id / 10.0);
+      gras_os_sleep(id / 100.0);
    }
    
    xbt_mutex_lock(mut_end);
@@ -120,8 +120,11 @@ int philosopher (int argc,char *argv[]) {
   
   INFO0("Enough waiting, spawn the threads");
   /* spawn threads */
-  for (i=0; i<philosopher_amount; i++)
-     philosophers[i] = xbt_thread_create(philo_thread,&id[i]);
+  for (i=0; i<philosopher_amount; i++) {
+     char *name = bprintf("thread %d",i);
+     philosophers[i] = xbt_thread_create(name,philo_thread,&id[i]);
+     free(name);
+  }
   
   /* wait for them */
   xbt_mutex_lock(mut_end);
@@ -131,8 +134,10 @@ int philosopher (int argc,char *argv[]) {
        
   INFO0("Cancel all childs");
   /* nuke them threads */
-  for (i=0; i<philosopher_amount; i++)
+  for (i=0; i<philosopher_amount; i++) {
+    INFO1("Canceling %p",philosophers[i]);
      xbt_thread_cancel(philosophers[i]);
+  }
 
   xbt_mutex_unlock(dead_end);
   gras_exit();