From 2896253b4c3c5b8ff5f4b831641337ecc80aa5a0 Mon Sep 17 00:00:00 2001 From: pmoura Date: Mon, 1 Jan 2007 17:20:56 +0000 Subject: [PATCH] Added error checking code to the predicates thread_exit/1 and thread_signal/2. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1763 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- pl/threads.yap | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pl/threads.yap b/pl/threads.yap index 625a00677..3c264a931 100644 --- a/pl/threads.yap +++ b/pl/threads.yap @@ -272,6 +272,9 @@ thread_detach(Id) :- thread_detach(Id) :- '$do_error'(existence_error(thread, Id),thread_detach(Id)). +thread_exit(Term) :- + var(Term), !, + '$do_error'(instantiation_error, thread_exit(Term)). thread_exit(Term) :- '$thread_self'(Id0), '$run_at_thread_exit'(Id0), @@ -595,16 +598,22 @@ thread_sleep(Time) :- thread_signal(Thread, Goal) :- var(Thread), !, '$do_error'(instantiation_error,thread_signal(Thread, Goal)). +thread_signal(Thread, Goal) :- + \+ integer(Thread), \+ atom(Thread), !, + '$do_error'(domain_error,thread_or_alias,thread_signal(Thread, Goal)). thread_signal(Thread, Goal) :- '$check_callable'(Goal,thread_signal(Thread,Goal)). thread_signal(Thread, Goal) :- - recorded('$thread_alias',[Id|Thread],_), !, + atom(Thread), + recorded('$thread_alias',[Id|Thread],_), + '$valid_thread'(Id), !, '$thread_signal'(Id, Goal). thread_signal(Thread, Goal) :- - integer(Thread), !, + integer(Thread), + '$valid_thread'(Thread), !, '$thread_signal'(Thread, Goal). thread_signal(Thread, Goal) :- - '$do_error'(type_error(integer,Thread),thread_signal(Thread, Goal)). + '$do_error'(existence_error(thread, Thread),thread_signal(Thread, Goal)). '$thread_signal'(Thread, Goal) :- ( recorded('$thread_signal',[Thread|_],R), erase(R), fail ; true ),