initialize a semaphore
cc [options] -Kthread file
int sema_init(sema_t *sema, int sema_count, int type, void *arg);
sema_init initializes the semaphore sema of type type
to protect sema_count resources.
Once initialized, the semaphore can be used any number of
times without being reinitialized.
Points to the semaphore to be initialized.
Specifies the initial number of resources to be protected by the semaphore.
sema_count must be greater than or equal to zero.
type can be set to one of the following values:
initialize the semaphore for threads within the current process
initialize the semaphore for threads across processes
arg should be set to NULL.
It is not currently used, but is reserved for future use.
Static semaphore initialization
A semaphore can be initialized statically
if its storage is zero-filled.
In this case, the semaphore is of type USYNC_THREAD,
its sema_count is 0
(that is, it is ``locked''; no resources are available)
and sema_init need not be called.
sema_post must be called to unlock the semaphore.
sema_init returns zero for success
and an error number for failure.
If the following condition is detected,
sema_init returns the corresponding value:
invalid argument specified
sema_init does not examine the sema argument
before initializing it.
If sema_init is called more than once for the same semaphore,
it will overwrite its state.
It is the user's responsibility to ensure that sema_init
is only called once for each semaphore.
Operations on semaphores initialized with
sema_init are not recursive;
a thread can block itself if
it attempts to reacquire a semaphore that it has already acquired.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004