Re: Aborting without killing
Torbjörn Lager <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CA+Y3JZhthThhnQJjSOu_U5FGJXsZbZiUOp_fgA8Mm+MA=9wDzQ@mail.gmail.com> |
Yes, thanks Alan, that is roughly what I'm going to do. Best, Torbjörn On Thu, Nov 14, 2013 at 4:59 PM, Alan Baljeu <[email protected]> wrote: > It appears the answer is to signal throw(Something), and design the thread > to catch that exception and hang around until you've retrieved the data, > maybe with a mutex to suspend execution until you release it to die on its > own. > > Alan Baljeu > ________________________________ > From: Torbjörn Lager <[email protected]> > To: Jan Wielemaker <[email protected]> > Cc: "[email protected]" <[email protected]> > Sent: Thursday, November 14, 2013 10:38:56 AM > Subject: Re: [SWIPL] Aborting without killing > > Thanks Jan, > > Ah, ok I get it now. The reason I want to stop the execution of a goal > (any goal) without killing the thread is that the dynamic db contains > clauses declared as thread_local, and I don't want them to disappear. > > Best, > Torbjörn > > On Thu, Nov 14, 2013 at 3:44 PM, Jan Wielemaker <[email protected]> wrote: >> On 11/14/2013 01:44 PM, Torbjörn Lager wrote: >>> Hi, >>> >>> Running (say) >>> >>> ?- repeat, fail. >>> >>> and executing thread_signal(main, abort) from another thread results in >>> >>> % Execution Aborted >>> >>> However, main is still running. >>> >>> However, running >>> >>> ?- thread_create((repeat, fail), ID, [alias(mymain)]). >>> >>> and executing thread_signal(mymain, abort) from another thread results >>> in mymain terminating with an exception '$aborted'. >>> >>> So, is there a way to abort a currently running goal without also >>> killing the thread that runs it? Or is the thread 'main' in the above >>> example killed and then recreated again? Is that what is happening? >> >> The main thread runs the C-function PL_toplevel(), which restarts the >> engine if it died on an exception. This is the same for other exceptions: >> an exception does not kill the interactive toplevel, but does kill any >> other thread when not caught. >> >> What is special about abort, which is implemented as throw('$aborted'), >> is that catch wraps the recover goal to re-throw the exception after >> the recover goal has terminated. So, you can cheat and make sure the >> recover goal never terminates :-) >> >> The big question of course is why you'd like to use abort if you don't >> want to kill the thread. If you just want it stop the thread doing some >> task and start another, simply do signal(Target, throw(stop)) and in the >> target, you do >> >> catch(Goal, stop, <whatever>) >> >> Cheers --- Jan > > > > -- > Torbjörn Lager > Professor of General and Computational Linguistics > Department of Philosophy, Linguistics and Theory of Science > University of Gothenburg > Box 200, SE-405 30 Gothenburg, Sweden > Phone: +46317864962 > > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog > > -- Torbjörn Lager Professor of General and Computational Linguistics Department of Philosophy, Linguistics and Theory of Science University of Gothenburg Box 200, SE-405 30 Gothenburg, Sweden Phone: +46317864962