From 7aab33a15306eae5bfe2043a1dec1f55ac9a2e8e Mon Sep 17 00:00:00 2001 From: vsc Date: Wed, 2 Apr 2008 15:13:16 +0000 Subject: [PATCH] fix at_exit and thread_at_exit (obs from Paulo Moura). git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2188 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- pl/threads.yap | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pl/threads.yap b/pl/threads.yap index ccafc604a..0eea953f7 100644 --- a/pl/threads.yap +++ b/pl/threads.yap @@ -48,7 +48,7 @@ '$thread_zombie_self'(Id0), !, '$close_thread'(Status, Detached, Id0). '$close_thread'(Status, Detached) :- !, - % one self will fail if it had messages + % zombie_self failed as it the thread was messages pending '$close_thread'(Status, Detached). @@ -59,7 +59,7 @@ ; recorda('$thread_exit_status', [Id0|Status], _) ). % format(user_error,'closing thread ~w~n',[v([Id0|Status])]). -'$close_thread'(Exception, Detached) :- +'$close_thread'(Exception, Detached, Id0) :- '$run_at_thread_exit'(Id0), ( Detached == true -> '$erase_thread_info'(Id0) @@ -327,20 +327,15 @@ thread_exit(Term) :- '$run_at_thread_exit'(Id0) :- recorded('$thread_at_exit',[Id0|AtExit],R), erase(R), - '$thread_top_goal'(AtExit), + catch(once(AtExit),_,fail), fail. '$run_at_thread_exit'(Id0) :- - findall(Hook, (recorded('$thread_exit_hook',[Id0|Hook],R), erase(R)), Hooks), - '$run_thread_hooks'(Hooks), + recorded('$thread_exit_hook',[Id0|Hook],R), erase(R), + catch(once(Hook),_,fail), fail. '$run_at_thread_exit'(Id0) :- message_queue_destroy(Id0). -'$run_thread_hooks'([]). -'$run_thread_hooks'([Hook|Hooks]) :- - '$thread_top_goal'(Hook), - '$run_thread_hooks'(Hooks). - thread_at_exit(Goal) :- '$check_callable'(Goal,thread_at_exit(Goal)), '$thread_self'(Id0),