Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

pthread_mutex_destroy(3P)

pthread_mutex_lock(3P)

pthread_mutex_unlock(3P)

pthread_mutex_trylock(3P)

PTHREAD_MUTEX_INIT(3P)               SysV               PTHREAD_MUTEX_INIT(3P)



NAME
     pthread_mutex_init - Creates a mutex

SYNOPSIS
     #include <pthread.h>

     int pthread_mutex_init (mutex, attr)
     pthread_mutex_t *mutex;
     pthread_mutexattr_t attr;

DESCRIPTION
     The pthread_mutex_init function creates a new mutex with attributes
     specified by the attr argument.  If attr is pthread_mutexattr_default,
     the default attributes are used.

     The arguments specify the following:

     mutex
          Specifies the address in which the ID for the new mutex will be
          stored.

     attr Specifies the attributes object to use in creating the new mutex.

     A mutex (from "mutual exclusion") is used to serialize the access of
     multiple threads to shared data.  Mutexes should only be used for
     synchronizing threads within a single process; using mutexes outside of a
     single process results in undefined behavior.

     Because a mutex lock is not a cancellation point, use mutexes to protect
     resources that will be held only for short fixed periods of time, where
     the absence of cancelability will not cause problems.  Use a condition
     variable to protect resources that need to be held exclusively for long
     periods of time.

NOTES
     This interface is based on draft 4 of the IEEE P1003.4a standard, and
     will be changed to conform to the final version.

DIAGNOSTICS
     Upon successful completion, the ID of the created mutex is stored at
     *mutex, and a value of 0 (zero) is returned.  Otherwise, no mutex is
     created, -1 is returned, and errno is set to indicate the error.

ERRORS
     If the pthread_mutex_init function fails, errno may be set to one of the
     following values:

     [EAGAIN]  The system lacks the resources necessary to create another
               mutex.

     [EAGAIN]  The new mutex cannot be created without exceeding the system-
               imposed limit on the total number of mutexes allowed for each
               user.

     [ENOMEM]  There is not enough memory to create the mutex object.  This is
               not a temporary condition.

     [EINVAL]  The value specified by the mutex or attr argument is invalid.

SEE ALSO
     pthread_mutex_destroy(3P), pthread_mutex_lock(3P),
     pthread_mutex_unlock(3P), pthread_mutex_trylock(3P)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026