STREAMS-UX Programmer's Guide (February 2007)

STREAMS Utilities Supported by HP-UX
Appendix B
223
NAME
SV_ALLOC () – Allocate and initialize a synchronization variable.
SYNOPSIS
#include <sys/stream.h>
sv_t *SV_ALLOC(int flag);
PARAMETERS
flag
Specifies whether the caller is willing to sleep waiting for memory. Valid flags are:
KM_SLEEP Caller willing to sleep.
KM_NOSLEEP Caller cannot sleep.
DESCRIPTION
SV_ALLOC dynamically allocates and initializes an instance of a synchronization variable. Synchronization
variables are synchronization primitives that are used to coordinate the execution of processes based on
asynchronous events. When allocated, these variables serve as points on which one or more processes can
block until an event occurs. Then one or all the processes can be unblocked at the same time. Any function
that blocks on a synchronization variable must be able to tolerate premature wakeups. If flag is set to
KM_SLEEP, the caller will sleep if necessary until sufficient memory is available. If flag is set to KM_NOSLEEP,
the caller will not sleep, but SV_ALLOC will return NULL if sufficient memory is not immediately available.
RETURN VALUES
Upon successful completion, SV_ALLOC returns a pointer to the newly allocated synchronization variable. If
KM_NOSLEEP is specified and sufficient memory is not immediately available, SV_ALLOC returns a NULL
pointer.
CONSTRAINTS
If KM_SLEEP is specified, SV_ALLOC() may sleep and can only be called from a thread context. If KM_NOSLEEP is
specified, spinlocks of STREAMS/UX user lock order can be held across this call and may be called from
thread or interrupt context.