Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finalize properties on AS.
[simgrid.git] / examples / gras / spawn / spawn.c
index 4b3489c..f2d74b1 100644 (file)
@@ -33,7 +33,8 @@ int worker(int argc, char *argv[]) {
     xbt_ex_t e;
     TRY {
       xbt_queue_shift_timed(todo,&chunk,0);
-    } CATCH(e) {
+    }
+    CATCH(e) {
       if (e.category != timeout_error) {
         RETHROW;
       }
@@ -42,7 +43,7 @@ int worker(int argc, char *argv[]) {
     if (!moretodo)
       break; // Do not break from within the CATCH, exceptions don't like it.
 
-    INFO2("Got [%d;%d] to do",chunk->min,chunk->max);
+    XBT_INFO("Got [%d;%d] to do",chunk->min,chunk->max);
     GRAS_BENCH_ALWAYS_BEGIN();
     int i;
     for (i=chunk->min;i<chunk->max;i++) {
@@ -57,7 +58,7 @@ int worker(int argc, char *argv[]) {
     GRAS_BENCH_ALWAYS_END();
     xbt_queue_push(done,&chunk);
   }
-  INFO0("No more work for me; bailing out");
+  XBT_INFO("No more work for me; bailing out");
 
   return 0;
 }
@@ -81,7 +82,7 @@ int server(int argc, char *argv[])
   done = xbt_queue_new(-1,sizeof(work_chunk_t));
 
 
-  INFO0("Prepare some work");
+  XBT_INFO("Prepare some work");
   for (i=0;i<maxint/perchunk;i++) {
     chunk = xbt_new0(s_work_chunk_t,1);
     chunk->min = i*perchunk;
@@ -90,15 +91,17 @@ int server(int argc, char *argv[])
     xbt_queue_push(todo,&chunk);
   }
 
-  INFO0("Spawn the kids");
+  XBT_INFO("Spawn the kids");
   for (i = 0; i < child_amount; i++) {
-    worker_args = xbt_new0(char *, 1);
+    char *name = bprintf("child%d",i);
+    worker_args = xbt_new0(char *, 2);
     worker_args[0] = xbt_strdup("child");
     worker_args[1] = NULL;
-    gras_agent_spawn(bprintf("child%d",i), NULL, worker, 1, worker_args, NULL);
+    gras_agent_spawn(name, worker, 1, worker_args, NULL);
+    free(name);
   }
 
-  INFO0("Fetch their answers");
+  XBT_INFO("Fetch their answers");
   for (i=0;i<maxint/perchunk;i++) {
     work_chunk_t chunk;
     xbt_strbuff_t buff = xbt_strbuff_new();
@@ -115,9 +118,10 @@ int server(int argc, char *argv[])
         xbt_strbuff_append(buff,",");
       xbt_strbuff_append(buff,number);
     }
-    INFO3("Primes in [%d,%d]: %s",chunk->min,chunk->max,buff->data);
+    XBT_INFO("Primes in [%d,%d]: %s",chunk->min,chunk->max,buff->data);
     xbt_strbuff_free(buff);
   }
+  gras_os_sleep(.1);/* Let the childs detect that there is nothing more to do */
   xbt_queue_free(&todo);
   xbt_queue_free(&done);