From 8a318a5e83d61f4533c72d82039cd4fc595cce3c Mon Sep 17 00:00:00 2001 From: pmoura Date: Mon, 31 Mar 2008 16:26:31 +0000 Subject: [PATCH] Updated the implementation of the thread_detach/1 predicate to help ensure that threads already terminated at the time of the call are destroyed instead of becoming zombie threads. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2173 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- pl/threads.yap | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pl/threads.yap b/pl/threads.yap index 2fe6677ec..fa71bf61e 100644 --- a/pl/threads.yap +++ b/pl/threads.yap @@ -147,18 +147,18 @@ thread_create(Goal, OutId, Options) :- '$thread_option'(Option, _, _, _, _, _, _, G0) :- var(Option), !, '$do_error'(instantiation_error,G0). +'$thread_option'(alias(Alias), Alias, _, _, _, _, _, G0) :- !, + ( \+ atom(Alias) -> '$do_error'(type_error(atom,Alias),G0) ; true ). '$thread_option'(stack(Stack), _, Stack, _, _, _, _, G0) :- !, ( \+ integer(Stack) -> '$do_error'(type_error(integer,Stack),G0) ; true ). '$thread_option'(trail(Trail), _, _, Trail, _, _, _, G0) :- !, ( \+ integer(Trail) -> '$do_error'(type_error(integer,Trail),G0) ; true ). '$thread_option'(system(System), _, _, _, System, _, _, G0) :- !, ( \+ integer(System) -> '$do_error'(type_error(integer,System),G0) ; true ). -'$thread_option'(alias(Alias), Alias, _, _, _, _, _, G0) :- !, - ( \+ atom(Alias) -> '$do_error'(type_error(atom,Alias),G0) ; true ). '$thread_option'(detached(Detached), _, _, _, _, Detached, _, G0) :- !, - ( Detached \== true, Detached \== false -> '$do_error'(domain_error(thread_option,Detached+[true,false]),G0) ; true ). + ( Detached \== true, Detached \== false -> '$do_error'(domain_error(thread_option,Detached+[true,false]),G0) ; true ). '$thread_option'(at_exit(AtExit), _, _, _, _, _, AtExit, G0) :- !, - ( \+ callable(AtExit) -> '$do_error'(type_error(callable,AtExit),G0) ; true ). + ( \+ callable(AtExit) -> '$do_error'(type_error(callable,AtExit),G0) ; true ). '$thread_option'(Option, _, _, _, _, _, _, G0) :- '$do_error'(domain_error(thread_option,Option),G0). @@ -314,6 +314,11 @@ thread_detach(Id) :- fail ; '$detach_thread'(Id0) + ), + ( recorded('$thread_exit_status', [Id0|_], _) -> + '$erase_thread_info'(Id0), + '$thread_destroy'(Id0) + ; true ). thread_exit(Term) :- @@ -324,7 +329,6 @@ thread_exit(Term) :- '$run_at_thread_exit'(Id0) :- recorded('$thread_at_exit',[Id0|AtExit],R), erase(R), - writeq(at_exit-AtExit), nl, '$thread_top_goal'(AtExit), fail. '$run_at_thread_exit'(Id0) :-