rw_wrlock(3synch) rw_wrlock(3synch)
NAME
rw_wrlock - acquire a reader-writer lock in write mode
SYNOPSIS
cc [options] -Kthread file
#include <synch.h>
int rw_wrlock(rwlock_t *lock);
Parameters
lock pointer to the reader-writer lock to be acquired
DESCRIPTION
rw_wrlock acquires the reader-writer lock pointed to by lock
in write mode.
Only one writer at a time can hold a reader-writer lock,
although any number of readers can hold the lock at any time.
Once a writer has requested the lock with rw_wrlock, all
subsequent requests for the lock in either read or write mode
are blocked.
When no other readers or writers hold the lock, rw_wrlock will
acquire the lock, and the caller will proceed. Any other
write and read requests for the lock will block until the
caller unlocks the lock with rw_unlock(3synch).
If the lock is held by any readers when rw_wrlock is called,
and no writer is waiting for the lock, the caller blocks until
all the current readers have released the lock. If the lock
is held by another writer, or if there are any other writers
already waiting for the lock, the caller blocks to wait for
the lock.
lock must previously have been initialized (see rwlock_init).
From the point of view of the application, this function is
atomic: even if interrupted by a signal or forkall, rw_wrlock
will not return until it holds the lock. As a consequence, if
rw_wrlock is interrupted, an error indication such as EINTR is
never returned to the user.
Return Values
rw_wrlock returns zero for success and an error number for
failure, as described below.
Copyright 1994 Novell, Inc. Page 1
rw_wrlock(3synch) rw_wrlock(3synch)
Errors
If any of the following conditions is detected, rw_wrlock
returns the corresponding value:
EINVAL Invalid argument specified.
ENOMEM Insufficient memory
USAGE
For consistency, locks acquired with rw_rdlock should be
released with rw_unlock.
Warnings
If a thread exits while holding a reader-writer lock, the lock
will not be unlocked, and other threads waiting for the lock
will wait forever. Similarly, if a process exits while
holding a USYNC_PROCESS reader-writer lock, the lock will not
be unlocked, and other processes waiting for the reader-writer
lock will wait forever.
REFERENCES
rwlock(3synch), rwlock_destroy(3synch), rwlock_init(3synch),
rw_rdlock(3synch), rw_tryrdlock(3synch), rw_trywrlock(3synch),
rw_unlock(3synch), synch(3synch)
Copyright 1994 Novell, Inc. Page 2