bugs in my locking discipline
authorbdemsky <bdemsky>
Fri, 16 Feb 2007 05:53:33 +0000 (05:53 +0000)
committerbdemsky <bdemsky>
Fri, 16 Feb 2007 05:53:33 +0000 (05:53 +0000)
Robust/src/IR/Flat/BuildCode.java
Robust/src/Runtime/garbage.c
Robust/src/Runtime/thread.c

index fc5d90ea427ec6d4a7fa9747ff32d99158773157..20f0892c1ec8e0ce812df383aeb9937c03f52c23 100644 (file)
@@ -175,6 +175,8 @@ public class BuildCode {
        outmethod.println("#include \"methodheaders.h\"");
        outmethod.println("#include \"virtualtable.h\"");
        outmethod.println("#include <runtime.h>");
+       if (state.THREAD)
+           outmethod.println("#include <thread.h>");
        if (state.main!=null) {
            outmethod.println("#include <string.h>");       
        }
@@ -249,6 +251,9 @@ public class BuildCode {
            } else {
                outmethod.println("  struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);");
            }
+           if (state.THREAD) {
+               outmethod.println("initializethreads();");
+           }
            outmethod.println("  for(i=1;i<argc;i++) {");
            outmethod.println("    int length=strlen(argv[i]);");
            if (GENERATEPRECISEGC) {
@@ -283,8 +288,15 @@ public class BuildCode {
                outmethod.println("   }");
                break;
            }
-           if (state.THREAD)
-               outmethod.println("pthread_exit();");
+           if (state.THREAD) {
+               outmethod.println("pthread_mutex_lock(&threadtable);");
+               outmethod.println("threadcount--;");
+               outmethod.println("pthread_mutex_unlock(&threadtable);");
+               outmethod.println("pthread_mutex_lock(&gclistlock);");
+               outmethod.println("pthread_cond_signal(&gccond);");
+               outmethod.println("pthread_mutex_unlock(&gclistlock);");
+               outmethod.println("pthread_exit(NULL);");
+           }
            outmethod.println("}");
        }
        if (state.TASK)
index a354351284ea726a7451bf10aed0e609ee212d5f..bbd2f04ffed28e8d71ddf084964b90a70234487a 100644 (file)
@@ -84,6 +84,8 @@ void collect(struct garbagelist * stackptr) {
     pthread_mutex_lock(&gclistlock);
     pthread_mutex_lock(&threadtable);
     if ((listcount+1)==threadcount) {
+      pthread_mutex_unlock(&threadtable);
+      pthread_mutex_unlock(&gclistlock);      
       break; /* Have all other threads stopped */
     }
     pthread_mutex_unlock(&threadtable);
@@ -286,6 +288,7 @@ void checkcollect(void * ptr) {
     struct listitem * tmp=stopforgc((struct garbagelist *)ptr);
     pthread_mutex_lock(&gclock);
     restartaftergc(tmp);
+    pthread_mutex_unlock(&gclock);
   }
 }
 
index 5e3b27cc8af8227d6a36584fb9898a01ca3a803c..99e79cef59514d75bee960580ca4e2870838388e 100644 (file)
@@ -31,6 +31,9 @@ void initthread(struct ___Thread___ * ___this___) {
   pthread_mutex_lock(&threadtable);
   threadcount--;
   pthread_mutex_unlock(&threadtable);
+  pthread_mutex_lock(&gclistlock);
+  pthread_cond_signal(&gccond);
+  pthread_mutex_unlock(&gclistlock);
 }
 
 void CALL01(___Thread______nativeCreate____, struct ___Thread___ * ___this___) {