nthm_blocked - test whether all open pipes are busy
#include <nthm/nthm.h>
int nthm_blocked ( int *err )
The nthm_blocked function tests whether or not nthm_select would block if it were called. This capability may be useful for polling the availability of readable pipes.
If there are pipes with threads tethered in the current scope that are still running but none ready to be read, then a successful call to nthm_blocked returns a non-zero value because nthm_select would have blocked if it were called. Otherwise, nthm_blocked returns a zero value either because the call was unsuccessful or because nthm_select would have returned immediately without blocking.
The value of *err is set to non-zero if it is zero on entry and nthm_blocked is unsuccessful for any reason, but is otherwise left unchanged. Errors indicate a failure of some internal consistency check due to memory corruption, misuse of the API, or a bug in nthm. Bug reports including error codes are welcome.
This example shows an event loop that interleaves reading of previously opened nthm pipes with other unspecified operations.
while (! err) if (nthm_blocked (&err)) { // do something other than waiting for pipes } else if (err) // not successful break; else if ((p = nthm_select (&err)) // not blocked { x = nthm_read (p, &err)) // do something with data x read from pipe p } else // all visible pipes have been read break;
nthm, nthm_open, nthm_send, nthm_select, nthm_read, 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_sync, nthm_strerror, nthm_busy, pthreads (7)
Dennis Furey (milonga@delayinsensitive.com)
https://github.com/gueststar/nthm