rwlock_init(3synch)


rwlock_init -- initialize a reader-writer lock

Synopsis

   cc [options] -Kthread file
   

#include <synch.h>

int rwlock_init(rwlock_t *rwlock, int type, void *arg);

Description

rwlock_init initializes the reader-writer lock pointed to by rwlock to be of type type and in the unlocked state. Once initialized, the lock can be used any number of times without being re-initialized.

Parameters


rwlock
pointer to reader-writer lock to be initialized

type
USYNC_THREAD or USYNC_PROCESS

arg
NULL (reserved for future use)

rwlock parameter

rwlock points to the reader-writer lock to be initialized.

type parameter

type can be set to one of the following values:

USYNC_THREAD
initialize the reader-writer lock for threads within the current process

USYNC_PROCESS
initialize the reader-writer lock for threads across processes

arg parameter

arg should be set to NULL. It is not currently used, but is reserved for future use.

Static reader-Writer initialization

In this implementation, a reader-writer lock can be initialized statically if its storage is zero-filled. In this case, the reader-writer lock is of type USYNC_THREAD, and rwlock_init need not be called.

Return values

rwlock_init returns zero for success and an error number for failure.

Errors

If the following condition is detected, the contents of rwlock are not changed, and rwlock_init returns the corresponding value:

EINVAL
Invalid type argument specified.

Warnings

rwlock_init does not examine the rwlock argument before initializing it. If rwlock_init is called more than once for the same reader-writer lock, it will overwrite its state. It is the user's responsibility to ensure that rwlock_init is only called once for each reader-writer lock.

Operations on locks initialized with rwlock_init are not recursive--a thread can deadlock if it attempts to reacquire a reader-writer lock that it already has acquired.

References

Intro(3synch), rwlock(3synch), rwlock_destroy(3synch), rw_rdlock(3synch), rw_tryrdlock(3synch), rw_trywrlock(3synch), rw_unlock(3synch), rw_wrlock(3synch)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004