Threads are now garbage collected correctly (hopefully).
authorschani <none@none>
Thu, 19 Nov 1998 13:39:49 +0000 (13:39 +0000)
committerschani <none@none>
Thu, 19 Nov 1998 13:39:49 +0000 (13:39 +0000)
src/threads/green/threads.c
src/threads/green/threads.h
threads/thread.c
threads/thread.h

index 851e2f9ac8dce5443f1b66a6196561648af2d588..622718b2f4141bb98698e48a4d1cc22dad63c19c 100644 (file)
@@ -128,13 +128,16 @@ initThreads(u1 *stackbottom)
 
     initLocks();
 
-    for (i = 0; i < MAXTHREADS; ++i)
+    for (i = 0; i < MAXTHREADS; ++i) {
                contexts[i].free = true;
+               contexts[i].thread = NULL;
+               heap_addreference((void**)&contexts[i].thread);
+       }
 
     /* Allocate a thread to be the main thread */
     liveThreads = the_main_thread = (thread*)builtin_new(loader_load(unicode_new_char("java/lang/Thread")));
     assert(the_main_thread != 0);
-       heap_addreference((void **) &liveThreads);
+       /* heap_addreference((void **) &liveThreads); */
     
     the_main_thread->PrivateInfo = 1;
     CONTEXT(the_main_thread).free = false;
@@ -155,6 +158,7 @@ initThreads(u1 *stackbottom)
 
        CONTEXT(the_main_thread).flags = THREAD_FLAGS_NOSTACKALLOC;
        CONTEXT(the_main_thread).nextlive = 0;
+       CONTEXT(the_main_thread).thread = the_main_thread;
        the_main_thread->single_step = 0;
        the_main_thread->daemon = 0;
        the_main_thread->stillborn = 0;
@@ -174,7 +178,7 @@ initThreads(u1 *stackbottom)
 
     mainThread = currentThread = the_main_thread;
 
-       heap_addreference((void**)&mainThread);
+       /* heap_addreference((void**)&mainThread); */
 
        /* Add thread into runQ */
        iresumeThread(mainThread);
@@ -200,6 +204,7 @@ startThread (thread* tid)
 
     tid->PrivateInfo = i + 1;
     CONTEXT(tid).free = false;
+       CONTEXT(tid).thread = tid;
     CONTEXT(tid).nextlive = liveThreads;
     liveThreads = tid;
     allocThreadStack(tid, threadStackSize);
@@ -532,7 +537,10 @@ killThread(thread* tid)
                freeThreadStack(tid);
 
                /* free context */
-               CONTEXT(tid).free = true;
+               if (tid != mainThread) {
+                       CONTEXT(tid).free = true;
+                       CONTEXT(tid).thread = NULL;
+               }
 
                /* Run something else */
                needReschedule = true;
index 1d37f613deec23825d350fbd97de7fe1a7145172..5a8f1359a76996ec49d06d47de6f134a101f6ad0 100644 (file)
@@ -1,3 +1,4 @@
+/* -*- mode: c; tab-width: 4; c-basic-offset: 4 -*- */
 /*
  * thread.h
  * Thread support.
@@ -41,7 +42,8 @@ struct _thread;
 
 typedef struct _ctx
 {
-    bool               free;           /* schani */
+    struct _thread    *thread;
+    bool               free;
     u1                 status;
     u1                 priority;
     u1*                restorePoint;
index 851e2f9ac8dce5443f1b66a6196561648af2d588..622718b2f4141bb98698e48a4d1cc22dad63c19c 100644 (file)
@@ -128,13 +128,16 @@ initThreads(u1 *stackbottom)
 
     initLocks();
 
-    for (i = 0; i < MAXTHREADS; ++i)
+    for (i = 0; i < MAXTHREADS; ++i) {
                contexts[i].free = true;
+               contexts[i].thread = NULL;
+               heap_addreference((void**)&contexts[i].thread);
+       }
 
     /* Allocate a thread to be the main thread */
     liveThreads = the_main_thread = (thread*)builtin_new(loader_load(unicode_new_char("java/lang/Thread")));
     assert(the_main_thread != 0);
-       heap_addreference((void **) &liveThreads);
+       /* heap_addreference((void **) &liveThreads); */
     
     the_main_thread->PrivateInfo = 1;
     CONTEXT(the_main_thread).free = false;
@@ -155,6 +158,7 @@ initThreads(u1 *stackbottom)
 
        CONTEXT(the_main_thread).flags = THREAD_FLAGS_NOSTACKALLOC;
        CONTEXT(the_main_thread).nextlive = 0;
+       CONTEXT(the_main_thread).thread = the_main_thread;
        the_main_thread->single_step = 0;
        the_main_thread->daemon = 0;
        the_main_thread->stillborn = 0;
@@ -174,7 +178,7 @@ initThreads(u1 *stackbottom)
 
     mainThread = currentThread = the_main_thread;
 
-       heap_addreference((void**)&mainThread);
+       /* heap_addreference((void**)&mainThread); */
 
        /* Add thread into runQ */
        iresumeThread(mainThread);
@@ -200,6 +204,7 @@ startThread (thread* tid)
 
     tid->PrivateInfo = i + 1;
     CONTEXT(tid).free = false;
+       CONTEXT(tid).thread = tid;
     CONTEXT(tid).nextlive = liveThreads;
     liveThreads = tid;
     allocThreadStack(tid, threadStackSize);
@@ -532,7 +537,10 @@ killThread(thread* tid)
                freeThreadStack(tid);
 
                /* free context */
-               CONTEXT(tid).free = true;
+               if (tid != mainThread) {
+                       CONTEXT(tid).free = true;
+                       CONTEXT(tid).thread = NULL;
+               }
 
                /* Run something else */
                needReschedule = true;
index 1d37f613deec23825d350fbd97de7fe1a7145172..5a8f1359a76996ec49d06d47de6f134a101f6ad0 100644 (file)
@@ -1,3 +1,4 @@
+/* -*- mode: c; tab-width: 4; c-basic-offset: 4 -*- */
 /*
  * thread.h
  * Thread support.
@@ -41,7 +42,8 @@ struct _thread;
 
 typedef struct _ctx
 {
-    bool               free;           /* schani */
+    struct _thread    *thread;
+    bool               free;
     u1                 status;
     u1                 priority;
     u1*                restorePoint;