bugs in my locking discipline
[IRC.git] / Robust / src / IR / Flat / BuildCode.java
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)