Files
mercury/tests/hard_coded/spawn_native_joinable.exp
Peter Wang 4ea65113d8 Add interface for joinable threads.
It is often necessary to be certain that a thread has terminated before
the rest of the program can continue. In some cases, signalling that a
thread is ABOUT to terminate (using any synchronisation device)
is insufficient: even after the last piece of Mercury code has run,
the thread still has additional cleanup code to run, which might include
arbitrary code in thread-specific data destructors, etc.

Introduce a predicate to create a joinable native thread,
and a predicate to wait for that thread to terminate (joining).

Joinable threads are only implemented for C backends for now.

library/thread.m:
    Add new predicates spawn_native_joinable and join_thread.

    Add a internal type thread_handle.

    Rename the internal type thread_id type to thread_desc,
    as thread_id is too similar to thread_handle.

tests/hard_coded/Mmakefile:
tests/hard_coded/spawn_native_joinable.exp:
tests/hard_coded/spawn_native_joinable.exp2:
tests/hard_coded/spawn_native_joinable.m:
    Add test case.

NEWS.md:
    Announce changes.
2024-02-26 13:18:45 +11:00

7 lines
92 B
Plaintext

a start
b start
a stop
b stop
a join result: ok({"a", 1234})
b join result: ok({"b", 1234})