Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Various cleanups.
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 12 Mar 2007 11:19:12 +0000 (11:19 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 12 Mar 2007 11:19:12 +0000 (11:19 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3238 48e7efb5-ca39-0410-a469-dd3cf9ba447f

testsuite/xbt/context_usage.c

index edc617d..44be306 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "xbt.h"
 #include "xbt/context.h"
+#include "gras_config.h" /* To know whether we're using threads or context */
 #include "xbt/fifo.h"
 
 xbt_context_t cA = NULL;
@@ -28,15 +29,16 @@ int fA(int argc, char** argv)
   printf("Here is fA: ");
   print_args(argc,argv);
 
-  printf("\tContext A: Yield\n");
-//  xbt_context_yield(); // FIXME: yielding to itself fails, no idea why
+/*   printf("\tContext A: Yield\n"); */
+/*   xbt_context_yield(); // FIXME: yielding to itself fails, no idea why */
    
+  printf("\tContext A: Push context B\n");
   xbt_fifo_push(fifo,cB);
-  printf("\tPush context B from context A\n");
 
-   printf("\tContext A: Yield\n");
+  printf("\tContext A: Yield\n");
   xbt_context_yield();
-  printf("\tContext A : bye\n");
+
+  printf("\tContext A: bye\n");
 
   return 0;
 }
@@ -47,13 +49,16 @@ int fB(int argc, char** argv)
   printf("Here is fB: ");
   print_args(argc,argv);
 
-//  printf("\tContext B: Yield\n");
-//  xbt_context_yield();
+/*   printf("\tContext B: Yield\n"); */
+/*   xbt_context_yield(); */
+
+  printf("\tContext B: Push context A\n");
   xbt_fifo_push(fifo,cA);
-  printf("\tPush context A from context B\n");
+
   printf("\tContext B: Yield\n");
   xbt_context_yield();
-  printf("\tContext B : bye\n");
+
+  printf("\tContext B: bye\n");
 
   return 0;
 }
@@ -64,10 +69,10 @@ int fC(int argc, char** argv)
   printf("Here is fC: ");
   print_args(argc,argv);
 
-
-  printf("\tContext C: Yield (and exit)\n");
+  printf("\tContext C: Yield\n");
   xbt_context_yield();
 
+  printf("\tContext C: bye\n");
 
   return 0;
 }
@@ -81,7 +86,12 @@ int main(int argc, char** argv)
   xbt_context_t context = NULL;
 
   printf("XXX Test the simgrid context API\n");
+#if CONTEXT_THREADS
+  printf("XXX Using threads as a backend.\n");
+#else /* use SUSv2 contexts */
+  printf("XXX Using SUSv2 contexts as a backend.\n");
   printf("    If it fails, try another context backend.\n    For example, to force the pthread backend, use:\n       ./configure --with-context=pthread\n\n");
+#endif
    
   xbt_init(&argc, argv);
 
@@ -92,19 +102,26 @@ int main(int argc, char** argv)
   fifo = xbt_fifo_new();
 
   printf("Here is context 'main'\n");
+  printf("\tPush context 'A' (%p) from context 'main'\n",cA);
+  xbt_fifo_push(fifo,cA); 
   xbt_context_start(cA);
-  printf("\tPush context 'A' from context 'main'\n");xbt_fifo_push(fifo,cA);
+
+  printf("\tPush context 'B' (%p) from context 'main'\n",cB);
+  xbt_fifo_push(fifo,cB);
   xbt_context_start(cB);
-  printf("\tPush context 'B' from context 'main'\n");xbt_fifo_push(fifo,cB);
-  xbt_context_start(cC);xbt_fifo_push(fifo,cC);
-  printf("\tPush context 'C' from context 'main'\n");xbt_fifo_push(fifo,cC);
+
+  printf("\tPush context 'C' (%p) from context 'main'\n",cC);
+  xbt_fifo_push(fifo,cC); 
+  xbt_context_start(cC);
 
   while((context=xbt_fifo_shift(fifo))) {
-    printf("Context main: Yield\n");
+    printf("Context main: schedule\n");
     xbt_context_schedule(context);
   }
 
+  printf("\tFreeing Fifo\n");
   xbt_fifo_free(fifo);
+  printf("\tExit & cleaning living threads\n");
   xbt_exit();
   
   cA=cB=cC=NULL;