HDK Technical Reference

Synchronization variables

Synchronization variables are synchronization primitives that are used to coordinate the execution of processes based on asynchronous events. When allocated, synchronization variables serve as points upon which one or more processes can block until an event occurs. Then one or all of the processes can be unblocked. at the same time.

In addition, you can set relative priorities for processes, to be used while running in the kernel after unblocking (waking up). see pri(D5).

Note that any function that blocks on a synchronization variable must be able to tolerate premature wakeups. In other words, the code must be written so that, after it is unblocked (awakened), it reexamines the condition on which it was blocked. This applies to the SV_WAIT(D3) and SV_WAIT_SIG(D3) as well as to sleep(D3).

The manual pages for functions and other information used for synchronization variables are listed below. These routines are available in ddi: 5 and higher.

Synchronous variable locking functions

Function Description
SV_ALLOC(D3) allocate and initialize a synchronization variable
SV_WAIT(D3) block on a synchronization variable
SV_WAIT_SIG(D3) like SV_WAIT, but can also be unblocked by a signal
SV_SIGNAL(D3) unblock one process blocked on a synchronization variable
SV_BROADCAST(D3) wake up all processes blocked on a synchronization variable
SV_DEALLOC(D3) deallocate an instance of a synchronization variable

Comparison of sleep and synchronization variables

Older drivers that were not multithreaded used the sleep(D3) and wakeup(D3) functions rather than the synchronization variables. The major differences between the use of sleep( ) and wakeup( ) in single-threaded drivers and the analogous (but by no means identical) synchronization variable routines used in multithreaded drivers are:

The following examples illustrate the difference between using sleep/wakeup in a single-threaded driver and a multithreaded version using SV_WAIT/SV_SIGNAL.

Synchronization with sleep/wakeup Using sleep/wakeup, the blocking code is:

   opl = spldisk();
   while (variable == FALSE)
   /* Critical code section */
The unblocking code is:
   variable = TRUE;

Synchronization with SV_WAIT/SV_SIGNAL Using synchronization variables, the blocking code is:

   opl = LOCK(samp_lock,pldisk);

while (variable == FALSE) { SV_WAIT(samp_sv, SAMP_PRI, samp_lock); LOCK(samp_lock, pldisk); }

/* Critical code section */

UNLOCK(samp_lock, opl);

The unblocking code is:
   opl = LOCK(samp_lock,pldisk);
   variable = TRUE;
   UNLOCK(samp_lock, opl);

© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005