usinitsema - initialize a semaphore
int usinitsema (usema_t *sema, int val);
usinitsema initializes the semaphore specified by sema. The count of the
semaphore is set to the value specified by val. A value of 0 implies no
available resources, and the first process that attempts a 'P' operation
(via uspsema) will block. This can be viewed as a synchronizing
semaphore, since the goal is to always have a process block until another
has completed an operation that the first process requires. Positive
values for val can be used for tracking a collection of resources. The
simplest case of a value of 1 implements the common mutual exclusion
semaphore, namely one and only one process will be permitted through a
semaphore at a time. Values greater than one imply that up to val
resources may be simultaneously used, but requests for more than val
resources cause the calling process to block until a resource comes free
(by a process holding a resource performing a usvsema).
Metering and debugging are reinitialized and the history logging
mechanism is set according to the global setting (see usconfig(3P)).
usinitsema should only be used for semaphores previously allocated using
. Note that usinitsema does not
check whether any process is currently waiting for the semaphore. Any
such information is lost. This means that any processes that are waiting
for the semaphore (either blocked or queued on a pollable semaphore) will
not be woken, nor will the internal counts kept in the operating system
usinitsema will fail if the following is true:
[EINVAL] val must be greater than or equal to 0 and less than
uscpsema(3P), usctlsema(3P), usfreesema(3P), usinit(3P), usnewsema(3P),
usnewpollsema(3P), uspsema(3P), usvsema(3P).
Upon successful completion, a value of 0 is returned. Otherwise, a value
of -1 is returned and errno is set to indicate the error.
PPPPaaaaggggeeee 1111 [ Back ]