Unix/Linux Go Back    

NetBSD 6.1.5 - man page for pthread_mutex_lock (netbsd section 3)

Linux & Unix Commands - Search Man Pages
Man Page or Keyword Search:   man
Select Man Page Set:       apropos Keyword Search (sections above)

PTHREAD_MUTEX(3)		   BSD Library Functions Manual 		 PTHREAD_MUTEX(3)

     pthread_mutex -- mutual exclusion primitives

     POSIX Threads Library (libpthread, -lpthread)

     #include <pthread.h>

     pthread_mutex_init(pthread_mutex_t * restrict mutex,
	 const pthread_mutexattr_t * restrict attr);

     pthread_mutex_destroy(pthread_mutex_t *mutex);

     pthread_mutex_lock(pthread_mutex_t *mutex);

     pthread_mutex_trylock(pthread_mutex_t *mutex);

     pthread_mutex_unlock(pthread_mutex_t *mutex);

     pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

     The pthread_mutex_init() function creates a new mutex, with attributes specified with attr.
     If attr is NULL, the default attributes are used.

     The macro PTHREAD_MUTEX_INITIALIZER can be used to initialize a mutex when the default
     attributes are appropriate and the mutex can be statically allocated.  The behavior is simi-
     lar to pthread_mutex_init() with attr specified as NULL, except that no error checking is

     The pthread_mutex_destroy() function frees the resources allocated for mutex.  It is possi-
     ble to reinitialize a destroyed mutex, but undefined behavior may follow if the destroyed
     object is otherwise referenced.

     The pthread_mutex_lock() function locks mutex.  If the mutex is already locked, the calling
     thread will block until the mutex becomes available.  The error conditions may vary depend-
     ing on the type of the mutex; see pthread_mutexattr(3) for additional details.

     The pthread_mutex_trylock() function locks mutex.	If the mutex is already locked,
     pthread_mutex_trylock() will not block waiting for the mutex, but will return an error con-

     The pthread_mutex_unlock() function unlocks an acquired mutex.  When operating with the
     default mutex type, undefined behavior follows if a thread tries to unlock a mutex that has
     not been locked by it, or if a thread tries to release a mutex that is already unlocked.

     Upon success all described functions return zero.	Otherwise, an error number will be
     returned to indicate the error.

     pthread_mutex_init() may fail if:

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

     [EINVAL]		The value specified by attr is invalid.

     [ENOMEM]		The process cannot allocate enough memory to initialize another mutex.

     pthread_mutex_destroy() may fail if:

     [EBUSY]		Mutex is locked by another thread.

     [EINVAL]		The value specified by mutex is invalid.

     pthread_mutex_lock() may fail if:

     [EDEADLK]		A deadlock would occur if the thread blocked waiting for mutex.

     [EINVAL]		The value specified by mutex is invalid.

     pthread_mutex_trylock() may fail if:

     [EBUSY]		Mutex is already locked.

     [EINVAL]		The value specified by mutex is invalid.

     pthread_mutex_unlock() may fail if:

     [EINVAL]		The value specified by mutex is invalid.

     [EPERM]		The current thread does not hold a lock on mutex.

     pthread(3), pthread_barrier(3), pthread_cond(3), pthread_mutexattr(3), pthread_rwlock(3),

     These functions conform to IEEE Std 1003.1-2001 (``POSIX.1'').

BSD					   July 8, 2010 				      BSD
Unix & Linux Commands & Man Pages : ©2000 - 2018 Unix and Linux Forums

All times are GMT -4. The time now is 12:44 AM.