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

Julien Fischer jfischer at opturion.com
Fri Jan 26 15:44:03 AEDT 2024


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.

What mercury_runtime_terminate() does is the following:

1. Runs any user-defined module finalizers.
2. Runs standard library finalization.
3. Some stuff to turn of debugging (if that is enabled).
4. Writes out trace counts (if the user has requested that).
5. Turns of profiling and writes out profiling results (if some form of
    profiling is enabled).
6. Writes out tabling statistics (if requested).
7. Shuts down engines (in low-level C .par grades)
8. Writes out memory usages reports (if requested by user)
9. Return mercury_exit_status to its caller.

I suspect the issue you are encountering is with (7), since that code
assumes that all engines are idle and if you still have threads running
at that point some of them won't be.

In the normal course of events, the runtime code that invokes main/2
blocks at the completion of main/2 until all threads terminate.

Julien.


More information about the users mailing list