[m-users.] Calling exit(3) from a foreign predicate

Sean Charles (emacstheviking) objitsu at gmail.com
Thu Jan 25 18:53:21 AEDT 2024


What a module accessible flag for global control then I guess?

:- module foo.

:- pred is_exit_requested.

:- implementation.

:- mutable (stop_flag, bool, no, ground, [...whats your app needs...]).

:- pragma promise_pure(stop_threads/0). 
:- pred stop_threads :-
    impure set_stop_flag(yes).


:- pragma promise_pure(iis_exit_requested/0). 
:- pred is_exit_requested is semidet.
is_exit_requested :-
    semipure get_stop_flag(yes).


then inside your threads you can just called   foo.is_exit_requested ?
This is off the top of my head, so I have probably made a few m istakes, it's early and I've not had my porridge yet, those are my excuses!

That's kind of what I was hinting at nefpre; external control, but I assumed you were passing two-way control structures but if the threads have no ears then thisd might be the solution / a solution?

Good luck VOlker, you always figure out!



> On 25 Jan 2024, at 05:05, Julien Fischer <jfischer at opturion.com> wrote:
> 
> 
> Hi,
> 
> On Wed, 24 Jan 2024, Volker Wysk wrote:
> 
>> Calling exit(3), without calling mercury_runtime_terminate() before, works.
>> All thread are terminated and the program exits. It's only
>> mercury_runtime_terminate() that blocks. I've read somewhere that it waits
>> for all threads to terminate. Is there another function which doesn't? I'd
>> like to properly shut down the Mercury runtime, if possible.
> 
> Yes, Mercury programs do not terminate until all threads created by
> calls to spawn/3 terminate; mercury_runtime_terminate() will block until
> this occurs. As it stands at the moment, you will need to arrange for
> any remaining threads to terminate.
> 
> Julien.
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org
> https://lists.mercurylang.org/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20240125/4ab31c42/attachment.html>


More information about the users mailing list