mutex_lock(3synch)


mutex_lock -- lock a mutex

Synopsis

   cc [options] -Kthread file
   

#include <synch.h>

int mutex_lock(mutex_t *mutex);

Description

mutex_lock locks the mutual exclusion lock (mutex) pointed to by mutex. If mutex is locked, the calling thread is blocked until mutex becomes available. When mutex_lock returns successfully, the caller has locked mutex.

Parameters


mutex
pointer to mutex to be locked

mutex must previously have been initialized, either by mutex_init, or statically (see mutex_init(3synch)).

From the point of view of the caller, mutex_lock is atomic: even if interrupted by a signal or forkall (see fork(2)), mutex_lock will not return until it holds the locked mutex. As a consequence, if mutex_lock is interrupted, an error indication such as EINTR is never returned to the caller.

Usage

Mutexes acquired with mutex_lock should be released with mutex_unlock.

Return values

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

Errors

If the following condition is detected, mutex_lock returns the corresponding value:

EINVAL
invalid argument specified

Warnings

If a thread exits while holding a mutex, the mutex will not be unlocked, and other threads waiting for the mutex will wait forever. Similarly, if a process exits while holding a USYNC_PROCESS mutex, the mutex will not be unlocked, and other processes or threads waiting for the mutex will wait forever.

References

fork(2), Intro(3synch), mutex(3synch), mutex_destroy(3synch), mutex_init(3synch), mutex_trylock(3synch), mutex_unlock(3synch)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004