diff --git a/C/threads.c b/C/threads.c index 0a3451a47..f74249453 100644 --- a/C/threads.c +++ b/C/threads.c @@ -143,14 +143,13 @@ thread_run(void *widp) { Term tgoal; Term tgs[2]; - int out; int myworker_id = *((int *)widp); start_thread(myworker_id); tgs[0] = Yap_FetchTermFromDB(ThreadHandle[worker_id].tgoal); tgs[1] = ThreadHandle[worker_id].tdetach; tgoal = Yap_MkApplTerm(FunctorThreadRun, 2, tgs); - out = Yap_RunTopGoal(tgoal); + Yap_RunTopGoal(tgoal); thread_die(worker_id, FALSE); return NULL; } diff --git a/pl/threads.yap b/pl/threads.yap index b591bea8e..5d42b78b7 100644 --- a/pl/threads.yap +++ b/pl/threads.yap @@ -33,21 +33,29 @@ '$thread_self'(Id), (Detached == true -> '$detach_thread'(Id) ; true), '$current_module'(Module), - '$system_catch'((G,'$close_thread'),Module,Exception,'$thread_exception'(Exception)). + '$system_catch'((G,'$close_thread'(Detached,true) ; '$close_thread'(Detached,false)),Module,Exception,'$thread_exception'(Exception,Detached)). '$top_thread_goal'(_) :- '$thread_self'(Id0), recorda('$thread_exit_status', [Id0|false], _), '$run_at_thread_exit'(Id0). -'$close_thread' :- +'$close_thread'(Detached, Status) :- '$thread_self'(Id0), - recorda('$thread_exit_status', [Id0|true], _), + (Detached == true -> + true + ; + recorda('$thread_exit_status', [Id0|Status], _) + ), '$run_at_thread_exit'(Id0). -'$thread_exception'(Exception) :- +'$thread_exception'(Exception,Detached) :- '$thread_self'(Id0), - recorda('$thread_exit_status', [Id0|exception(Exception)], _), + (Detached == true -> + true + ; + recorda('$thread_exit_status', [Id0|exception(Exception)], _) + ), '$run_at_thread_exit'(Id0). thread_create(Goal, Id) :-