Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Display more info
[simgrid.git] / examples / gras / synchro / philosopher.c
index e6652e9..7559027 100644 (file)
@@ -94,9 +94,6 @@ int philosopher (int argc,char *argv[]) {
   gras_init(&argc,argv);
   xbt_assert0(argc>=2,"This program expects one argument (the amount of philosophers)");
 
-  INFO0("Wait 1 sec to check that gras_os_sleep do works");
-  gras_os_sleep(1);
-   
   /* initializations of the philosopher mecanisms */
   philosopher_amount = atoi(argv[1]);
   state = xbt_new0(int,philosopher_amount); 
@@ -118,10 +115,13 @@ int philosopher (int argc,char *argv[]) {
   dead_end = xbt_mutex_init();
   xbt_mutex_lock(dead_end);
   
-  INFO0("Enough waiting, spawn the threads");
+  INFO2("Spawn the %d threads (%d lunches scheduled)", philosopher_amount, lunch_amount);
   /* 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 +131,9 @@ int philosopher (int argc,char *argv[]) {
        
   INFO0("Cancel all childs");
   /* nuke them threads */
-  for (i=0; i<philosopher_amount; i++)
-     xbt_thread_cancel(philosophers[i]);
+  for (i=0; i<philosopher_amount; i++) {
+    xbt_thread_cancel(philosophers[i]);
+  }
 
   xbt_mutex_unlock(dead_end);
   gras_exit();