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

Julien Fischer <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
On Thu, 20 Jul 2023, Volker Wysk wrote:

> Just a short question:
>
> May a foreign predicate call the exit(3) function?

A foreign predicate can do that, there's nothing the Mercury compiler
can do to stop it.

> Or does Mercury need a proper shutdown?

Calling exit() directly will bypass the usual shutdown of the Mercury
runtime. Among the effects of that will be:

- Finalizers will not be run.
- The Mercury exit status will not be returned to the OS.

If for some reason, you do want to call exit() from a foreign predicate,
I would suggest something like the following:

      exit(mercury_runtime_terminate());

(mercury_runtime_terminate() is declared in runtime/mercury_wrapper.h)

The only time I've wanted to something similar was from within the
event loop of the old GLUT library, where there that library provided
no way of getting out of the event loop. (See the quit/2 predicate
in extras/graphics/mercury_glut/glut.m.)

In general, given the choice, I would simply throw an exception that is
caught be a top-level exception handler in main/2 and exit (normally)
that way.

Julien.
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.