more changes towards oooJava version 2
[IRC.git] / Robust / src / Runtime / workschedule.c
index f342bedc1123808477c71c0270c8456b88ebfed5..8ed10ef0108c79d679b08c16eac0bc335794e657 100644 (file)
@@ -8,6 +8,7 @@
 #include "coreprof/coreprof.h"
 #ifdef RCR
 #include "rcr_runtime.h"
+#include "trqueue.h"
 #endif
 
 // NOTE: Converting this from a work-stealing strategy
@@ -55,7 +56,7 @@ __thread int oid;
 
 #ifdef RCR
 #include "trqueue.h"
-__thread struct trqueue * TRqueue;
+__thread struct trQueue * TRqueue=NULL;
 #endif
 
 
@@ -85,8 +86,9 @@ void* workerMain( void* arg ) {
   pthread_attr_t nattr;  
   pthread_attr_init(&nattr);
   pthread_attr_setdetachstate(&nattr, PTHREAD_CREATE_DETACHED);
-  TRqueue=allocTR();
-  int status = pthread_create( &(workerDataArray[i].workerThread), 
+  if (TRqueue==NULL)
+    TRqueue=allocTR();
+  int status = pthread_create( &thread,
                               NULL,
                               workerTR,
                               (void*) TRqueue);
@@ -184,6 +186,12 @@ void workScheduleInit( int numProcessors,
   // this code) will become a worker thread after setup
   workerDataArray = RUNMALLOC( sizeof( WorkerData ) * (numWorkers+1) );
 
+#ifdef RCR
+  //make sure the queue is initialized
+  if (TRqueue==NULL)
+    TRqueue=allocTR();
+#endif
+
   for( i = 0; i < numWorkers; ++i ) {
 
     // the original thread is ID 1, start counting from there