Home > pthread mutex init ebusy > pthread_mutex_init ebusy error

Pthread_mutex_init Ebusy Error

Contents

const pthread_mutexattr_t *attr); int pthread_mutex_destroy(pthread_mutex_t *mutex); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; DESCRIPTION The pthread_mutex_init() function initialises the mutex referenced by mutex with attributes specified by attr. If attr is

Pthread_mutex_init Example

NULL, the default mutex attributes are used; the effect is the pthread_mutex_init man same as passing the address of a default mutex attributes object. Upon successful initialisation, the state of pthread_mutex_init recursive the mutex becomes initialised and unlocked. Attempting to initialise an already initialised mutex results in undefined behaviour. The pthread_mutex_destroy() function destroys the mutex object referenced by mutex; the

Pthread_mutex_initializer Example

mutex object becomes, in effect, uninitialised. An implementation may cause pthread_mutex_destroy() to set the object referenced by mutex to an invalid value. A destroyed mutex object can be re-initialised using pthread_mutex_init(); the results of otherwise referencing the object after it has been destroyed are undefined. It is safe to destroy an initialised mutex that is unlocked.

Pthread_mutexattr_t

Attempting to destroy a locked mutex results in undefined behaviour. In cases where default mutex attributes are appropriate, the macro PTHREAD_MUTEX_INITIALIZER can be used to initialise mutexes that are statically allocated. The effect is equivalent to dynamic initialisation by a call to pthread_mutex_init() with parameter attr specified as NULL, except that no error checks are performed. RETURN VALUE If successful, the pthread_mutex_init() and pthread_mutex_destroy() functions return zero. Otherwise, an error number is returned to indicate the error. The [EBUSY] and [EINVAL] error checks, if implemented, act as if they were performed immediately at the beginning of processing for the function and cause an error return prior to modifying the state of the mutex specified by mutex. ERRORS The pthread_mutex_init() function will fail if: [EAGAIN] The system lacked the necessary resources (other than memory) to initialise another mutex. [ENOMEM] Insufficient memory exists to initialise the mutex. [EPERM] The caller does not have the privilege to perform the operation. The pthread_mutex_init() function may fail if: [EBUSY] The implementati

| Errors | Attributes | See Also Name pthread_mutex_init, pthread_mutex_destroy– initialize or destroy a mutex Synopsis cc –mt [ flag... ] file... –lpthread pthread_cond_init [ library... ] #include int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t

Pthread_mutex Example

*restrict attr); int pthread_mutex_destroy(pthread_mutex_t *mutex); pthread_mutex_t mutex= PTHREAD_MUTEX_INITIALIZER; Description The pthread_mutex_init() function initializes the mutex referenced by default mutex attributes mutex with attributes specified by attr. If attr is NULL, the default mutex attributes are used; the effect is the same as passing the address of a http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_mutex_init.html default mutex attributes object. Upon successful initialization, the state of the mutex becomes initialized and unlocked. Except for robust mutexes, attempting to initialize an already initialized mutex results in undefined behavior. The pthread_mutex_destroy() function destroys the mutex object referenced by mutex; the mutex object becomes, in effect, uninitialized. A destroyed mutex object can be re-initialized http://docs.oracle.com/cd/E19253-01/816-5168/6mbb3hrm7/index.html using pthread_mutex_init(); the results of otherwise referencing the object after it has been destroyed are undefined. It is safe to destroy an initialized mutex that is unlocked. Attempting to destroy a locked mutex results in undefined behavior. In cases where default mutex attributes are appropriate, the macro PTHREAD_MUTEX_INITIALIZER can be used to initialize mutexes that are statically allocated. The effect is equivalent to dynamic initialization by a call to pthread_mutex_init() with parameter attr specified as NULL, except that no error checks are performed. Return Values If successful, the pthread_mutex_init() and pthread_mutex_destroy() functions return 0. Otherwise, an error number is returned to indicate the error. Errors The pthread_mutex_init() function will fail if: EAGAIN The system lacked the necessary resources (other than memory) to initialize another mutex. EBUSY An attempt was detected to re-initialize a robust mutex previously initialized but not yet destroyed. See pthread_mutexattr_setrobust_np(3C). EINVAL An attempt was detected to re-initialize a robust mutex previously initialized with a different set of attributes. See pthread_mutexattr_setrobust_np(3C). ENOME

= PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t recmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; pthread_mutex_t errchkmutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr); int pthread_mutex_lock(pthread_mutex_t *mutex); int pthread_mutex_trylock(pthread_mutex_t *mutex); int pthread_mutex_unlock(pthread_mutex_t *mutex); int pthread_mutex_destroy(pthread_mutex_t *mutex); DESCRIPTION A mutex is a MUTual EXclusion device, and is useful for protecting shared data structures from concurrent modifications, and implementing critical sections and monitors. A mutex has two possible states: unlocked (not owned by any thread), and locked (owned by one thread). A mutex can never be owned by two different threads simultaneously. A thread attempting to lock a mutex that is already locked by another thread is suspended until the owning thread unlocks the mutex first. pthread_mutex_init initializes the mutex object pointed to by mutex according to the mutex attributes specified in mutexattr. If mutexattr is NULL, default attributes are used instead. The LinuxThreads implementation supports only one mutex attributes, the mutex kind, which is either ``fast'', ``recursive'', or ``error checking''. The kind of a mutex determines whether it can be locked again by a thread that already owns it. The default kind is ``fast''. See pthread_mutexattr_init(3) for more information on mutex attributes. Variables of type pthread_mutex_t can also be initialized statically, using the constants PTHREAD_MUTEX_INITIALIZER (for fast mutexes), PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP (for recursive mutexes), and PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP (for error checking mutexes). pthread_mutex_lock locks the given mutex. If the mutex is currently unlocked, it becomes locked and owned by the calling thread, and pthread_mutex_lock

 

Related content

No related pages.