Index of Section 2 Manual Pages

Interix / SUApthread_mutex_unlock.2Interix / SUA

pthread_mutex_unlock(2)                         pthread_mutex_unlock(2)

  pthread_mutex_lock()

  NAME

    pthread_mutex_lock(), pthread_mutex_trylock(), pthread_mutex_unlock() -
    lock and unlock a mutex object

  SYNOPSIS

    #include 

    int pthread_mutex_lock(pthread_mutex_t *mutex);
    int pthread_mutex_trylock(pthread_mutex_t *mutex);
    int pthread_mutex_unlock(pthread_mutex_t *mutex);

  DESCRIPTION

    The pthread_mutex_lock(2) function locks the mutex object referenced by
    the mutex argument. If the mutex is already locked, the calling thread is
    blocked until the mutex is unlocked. When pthread_mutex_lock() returns,
    the specified mutex object is locked and owned by the calling thread.

    If the mutex was created with the type attribute set to
    PTHREAD_MUTEX_NORMAL, pthread_mutex_lock does not attempt to detect a
    deadlock condition caused by an attempt to lock an already locked mutex.
    If a thread attempts to unlock a thread that is not unlocked or that it
    did not lock, the results will be unpredictable.

    Error checking is provided if the type attribute is set to
    PTHREAD_MUTEX_ERRORCHECK, and pthread_mutex_lock will return an error if
    an attempt is made to lock a mutex that is already locked. An error occurs
    if a thread attempts to unlock a thread that is not unlocked or that it
    has not locked.

    When the type attribute is set to PTHREAD_MUTEX_RECURSIVE, the mutex
    maintains a lock count. The first time a thread locks a mutex, the lock
    count is set to 1 (one). Each time a thread locks the mutex, the lock
    count is incremented by one, and each time a thread unlocks the mutex, the
    lock count is decremented by one. When the lock count reaches zero, the
    mutex becomes available to other threads for use. An error occurs if a
    thread attempts to unlock a thread that is not unlocked or that it has not
    locked.

    If the type attribute is set to PTHREAD_MUTEX_DEFAULT, attempting to lock
    a mutex that is already locked will produce unexpected results.

    The pthread_mutex_trylock(2) function is identical to pthread_mutex_lock()
    except that if the mutex is already locked by the calling thread or any
    other thread, pthread_mutex_trylock() returns immediately. If the mutex
    type attribute is set to PTHREAD_MUTEX_RECURSIVE and the mutex is owned by
    the calling thread, the lock count is incremented by one and the
    pthread_mutex_trylock() function immediately returns zero, indicating
    success.

    The pthread_mutex_unlock(2) function unlocks the mutex referenced by
    mutex. The manner in which this occurs depends on the type attribute of
    the mutex. If the type attribute is set to PTHREAD_MUTEX_RECURSIVE, the
    mutex becomes available when the lock count reaches zero and the calling
    thread has no more locks on the mutex. If there are threads blocked on the
    mutex, and the call to pthread_mutex_unlock() releases the mutex, the
    scheduling policy determines which thread acquires the mutex.

    If a signal is sent to a thread waiting for a mutex, when the thread
    returns from the signal handler, it continues to wait on the mutex as
    though it had not been interrupted.

  RETURN VALUES

    On success, the pthread_mutex_lock() and pthread_mutex_unlock() functions
    return 0; otherwise, an error code is returned.

    The pthread_mutex_trylock() function returns 0 if a lock on the mutex is
    acquired; otherwise, an error code is returned.

  ERRORS

    The pthread_mutex_lock() and pthread_mutex_trylock() functions can fail
    for the following reason:

    [EINVAL]
        The mutex was created with the protocol attribute set to
        PTHREAD_PRIO_PROTECT and the calling thread's priority is higher than
        the mutex's current priority ceiling.

    The pthread_mutex_trylock() function can fail for the following reason:

    [EBUSY]
        The mutex is already locked.

    The pthread_mutex_lock() function can fail for the following reason:

    [EDEADLK]
        The calling thread already owns the mutex.

    The pthread_mutex_unlock() function can fail for the following reason:

    [EPERM]
        The calling thread does not own the mutex.

    All three functions can fail for the following reasons:

    [EINVAL]
        The mutex argument does not refer to an initialized mutex object.

    [EAGAIN]
        The mutex could not be locked because the maximum number of locks on
        the mutex has been reached.

    These functions do not return [EINTR].

  SEE ALSO

    pthread_mutex_destroy()

    pthread_mutex_timedlock()

  USAGE NOTES

    All of these functions are thread safe.

    None of these functions are async-signal safe.


Interix / SUAHosted at SUA Community for Interix, SUA and SFUInterix / SUA