Pthread Mutex Init Error Check
Contents |
- operations on mutexes Synopsis #include
Pthread Mutex Attributes
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 pthread mutex init example *mutex); int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abs_timeout); int pthread_mutex_unlock(pthread_mutex_t *mutex); int pthread_mutex_consistent(pthread_mutex_t *mutex); int pthread_mutex_destroy(pthread_mutex_t *mutex); Description A mutex
Pthread Mutex Initializer
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). pthread cond init 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 type of a mutex determines whether it can be locked again by a thread that already owns it. The default type is “normal�. 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 normal “fast� mutexes), PTHREAD_RECURSIVE_MUTEX_INITIALIZER (for recursive mutexes), and PTHREAD_ERRORCHECK_MUTEX_INITIALIZER (for er
the interface may not be implemented on Linux. Name pthread_mutex_destroy, pthread_mutex_init - destroy and initialize a mutex Synopsis #include
Pthread Mutex Lock
pthread_mutex_destroy(pthread_mutex_t *mutex); int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr); pthread_mutex_t
Pthread_mutex_init Example
mutex = PTHREAD_MUTEX_INITIALIZER; Description The pthread_mutex_destroy() function shall destroy the mutex object referenced by mutex; the mutex pthread mutex destroy object becomes, in effect, uninitialized. An implementation may cause pthread_mutex_destroy() to set the object referenced by mutex to an invalid value. A destroyed mutex object can be reinitialized https://www.sourceware.org/pthreads-win32/manual/pthread_mutex_init.html using pthread_mutex_init(); the results of otherwise referencing the object after it has been destroyed are undefined. It shall be safe to destroy an initialized mutex that is unlocked. Attempting to destroy a locked mutex results in undefined behavior. The pthread_mutex_init() function shall initialize the mutex referenced by mutex with attributes specified by attr. If attr is NULL, https://linux.die.net/man/3/pthread_mutex_init the default mutex attributes are used; the effect shall be the same as passing the address of a default mutex attributes object. Upon successful initialization, the state of the mutex becomes initialized and unlocked. Only mutex itself may be used for performing synchronization. The result of referring to copies of mutex in calls to pthread_mutex_lock(), pthread_mutex_trylock(), pthread_mutex_unlock(), and pthread_mutex_destroy() is undefined. Attempting to initialize an already initialized 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 shall be 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 Value If successful, the pthread_mutex_destroy() and pthread_mutex_init() functions shall return zero; otherwise, an error number shall be 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 s
barriers, and condition variables. The pthread APIs can simplify porting applications from a POSIX environment to SYS/BIOS, as well as allowing the same code to be compiled to run in a POSIX environment and with SYS/BIOS. As the pthread APIs are built on top of the SYS/BIOS Task and Semaphore modules, some of the APIs can be called from SYS/BIOS Tasks. This page provides brief descriptions of the APIs supported by SYS/BIOS and any SYS/BIOS-specific details. For more detail, see the official specification and documentation of the generic implementation. Contents 1 Adding SYS/BIOS Support for POSIX Threads 2 POSIX Threads 2.1 pthread_attr APIs 2.1.1 Initialize and destroy attributes 2.1.2 Get and set the thread attributes detach state 2.1.3 Get and set stack attributes 2.1.4 Get and set thread priority attributes 2.2 pthread APIs 2.2.1 Create thread 2.2.2 Detach or join a thread 2.2.3 Cancel, exit, and cleanup 2.2.4 Get and set a thread’s priority 2.2.5 Miscellaneous other thread APIs 3 POSIX Mutexes 3.1 Mutex Types 3.2 Mutex Protocols 3.3 pthread_mutexattr APIs 3.3.1 Initialize and de-initialize a pthread_mutexattr_t object 3.3.2 Get and set mutex type, protocol, and priority ceiling attributes 3.4 pthread_mutex APIs 3.4.1 Initialize and de-initialize mutexes 3.4.2 Get and set mutex priority ceilings 3.4.3 Lock a mutex 3.4.4 Unlock a mutex 4 POSIX Barriers 4.1 pthread_barrierattr APIs 4.2 pthread_barrier APIs 5 POSIX Condition Variables 5.1 pthread_condattr APIs 5.2 pthread_cond APIs 5.2.1 Initialization and destruction 5.2.2 Waiting on a condition variable 5.2.3 Signaling a condition variable 6 POSIX Read-Write Locks 6.1 pthread_rwlockattr APIs 6.2 pthread_rwlock APIs 6.2.1 Initialize and destroy locks 6.2.2 Acquire a lock for reading 6.2.3 Acquire a lock for writing 6.2.4 Unlock a read-write lock 7 Clock APIs 8 Message Queues 9 Semaphores 10 Timers 1