Skip to content

Commit

Permalink
Merge pull request #362 from Jafaral/fix-program-gc
Browse files Browse the repository at this point in the history
runtime: don't exit the main thread if a coexp attempted to gc it
  • Loading branch information
Don-Ward authored Feb 22, 2024
2 parents a031a82 + 30ebc09 commit 090d47a
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/runtime/rcoexpr.r
Original file line number Diff line number Diff line change
Expand Up @@ -577,19 +577,25 @@ void coclean(struct b_coexpr *cp) {
if (!IS_TS_THREAD(cp->status) || cp->alive==-1){
CURTSTATE();
cp->alive = -1; /* signal thread to exit */
#ifdef Concurrent
if (cp->id==curtstate->c->id){
/*
* If the thread is cleaning itself, exit, what about tls chain?
*/
cp->have_thread = 0;
#ifndef NO_COEXPR_SEMAPHORE_FIX
if (cp->semp) {SEM_CLOSE(cp->semp); cp->semp = NULL;}
#endif /* NO_COEXPR_SEMAPHORE_FIX */
pthread_exit(0);
}
if (cp == curtstate->c) {
/*
* If the thread is cleaning itself, exit, what about tls chain?
*/
cp->alive = -1; /* signal thread to exit */
cp->have_thread = 0;
#ifndef NO_COEXPR_SEMAPHORE_FIX
if (cp->semp) {SEM_CLOSE(cp->semp); cp->semp = NULL;}
#endif /* NO_COEXPR_SEMAPHORE_FIX */
pthread_exit(0);
} else if (cp->id == 1 && cp->id == curtstate->c->id) {
/* FIXME: Main thread, should just return? */
return;
}
#endif /* Concurrent */
cp->alive = -1; /* signal thread to exit */
if (cp->have_thread){
sem_post(cp->semp); /* unblock it */
THREAD_JOIN(cp->thread, NULL); /* wait for thread to exit */
Expand Down

0 comments on commit 090d47a

Please sign in to comment.