nthm_sync - wait for all threads created by nthm to exit
#include <nthm/nthm.h>
void nthm_sync ( int * err )
This function blocks the caller until all threads created by nthm_open or nthm_send have exited. Although the preferred means of synchronizing with threads created by nthm_open is to use nthm_select or nthm_read, and although explicit synchronization with threads created by nthm_send is not normally necessary, using nthm_sync to synchronize with the latter is appropriate when they use resources reclaimed by the caller.
The *err parameter is assigned a non-zero error code by nthm_sync if it is zero on entry and if an error is detected, but is left unchanged otherwise. No error code is ever assigned by nthm_sync unless nthm detects an internal error, whose code may range from -NTHM_MIN_ERR to -NTHM_MAX_ERR. Internal errors may indicate memory corruption, misuse of the API, or a bug in nthm. Bug reports including error codes are welcome.
In an application program containing this fragment, the function f always observes a non-zero value of global_resource even though the caller clears it after starting the thread, because the caller first waits for the thread to exit by calling nthm_sync.
static int global_resource = 1; void f (void *x) { if (! global_resource) printf ("nthm_sync didn't work\\n"); } // ... main thread below err = 0; nthm_send ((nthm_slacker) &f, x, &err); nthm_sync (&err); global_resource = 0; if (err) printf ("%s\\n", nthm_strerror (err)); exit (err ? EXIT_FAILURE : EXIT_SUCCESS);
nthm, nthm_open, nthm_read, nthm_select, nthm_truncate, nthm_truncate_all, nthm_truncated, nthm_enter_scope, nthm_exit_scope, nthm_kill, nthm_kill_all, nthm_killed, nthm_untether, nthm_tether, nthm_blocked, nthm_busy, nthm_send, nthm_strerror, pthreads (7), ulimit (1), atexit (3)
Dennis Furey (milonga@delayinsensitive.com)
https://github.com/gueststar/nthm