Semaphores are here defined as values that reside in shared heaps ([root:Netmcore_heap]), for example in the header field of [root:Netmcore_array] or somewhere else in heap-allocated data structures.
In order to ensure that the semaphore is in the heap, the
create must be used to initialize it
create requires a mutator as argument, this is
only possible by calling
create from the callback of
Semaphores are special values, and cannot be copied or moved.
Note that [root:Netsys_posix] provides wrappers for direct use of the semaphore functionality of the OS. These wrappers, however, cannot be used together with heaps, because semaphores are there represented as bigarrays, which cannot be pushed to heaps. This module here uses a trick to make it possible nevertheless.
A dummy semaphore is non-functional, but can be used to put something
Increments the semaphore by one, and notifies one of the waiting processes.
Decrements the semaphore by one. Semaphores cannot become negative. If the semaphore is already 0, the wait behavior defines how to go on:
Waiting is restarted after running a signal handler.