Re: Aborting without killing
Torbjörn Lager <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CA+Y3JZigxk9huaYeG4n3z2j+u+nFM-Ci1NR__27ftRbFXEryVg@mail.gmail.com> |
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