pshared
PTHREAD_PROCESS_SHARED
PTHREAD_PROCESS_PRIVATE
May be shared if in shared memory.
Cannot be shared.
References: 3.2,5.2.1
Headers: <pthread.h>
Errors: [EINVAL]attrinvalid.
Hint:
pthread_mutexattr_init
int pthread_mutexattr_init (
pthread_mutexattr_t *attr);
Initialize a mutex attributes object with default attributes.
References: 3.2,5.2.1
Headers: <pthread.h>
Errors: [ENOMEM] insufficient memory for attr.
Hint: Use to define mutex types.
pthread_mutexattr_setpshared............................................... [_POSIX_THREAD_PROCESS_sHARED ]
int pthread_mutexattr_setpshared (
pthread_mutexattr_t *attr,
int pshared);
Mutexes created with attr can be shared between processes if the pthread_mutex_t variable is allocated in memory shared by the processes.
pshared
PTHREAD_PROCESS_SHARED
May be shared if in shared memory.
PTHREAD_PROCESS_PRIVATE
Cannot be shared.
References: 3.2,5.2.1
Headers: <pthread.h>
Errors: [EINVAL] attr or detachstate invalid.
Hint:
pthread_mutex_destroy
int pthread_mutex_destroy (
pthread_mutex_t *mutex);
Destroy a mutex that you no longer need.
References: 3.2,5.2.1
Headers: <pthread.h>
Errors: [EBUSY] mutex is in use.
[EINVAL] mutex is invalid. Hint: Safest after unlocking mutex, when no other threads will lock.
pthread_mutex_init
int pthread_mutex_init ( pthread_mutex_t const pthread_mutexattr_t
*mutex, *attr);
Initialize a mutex. The attr argument specifies optional creation attributes.
References:
Headers:
Errors:
Hint:
3.2, 5.2.1 <pthread.h>
[EAGAIN] insufficient resources (other than memory).
[ENOMEM] insufficient memory.
[EPERM] no privilege to perform operation.
[EBUSY] mutex is already initialized.
[EINVAL] attr is invalid.
Use static initialization instead, if possible.
pthread_mutex_lock
int pthread_mutex_lock (
pthread_mutex_t *mutex);
Lock a mutex. If the mutex is currently locked, the calling thread is blocked until mutex is unlocked. On return, the thread owns the mutex until it calls pthread_ mutex_unlock.
References: 3.2, 5.2.1 Headers: <pthread.h>
Errors: [EINVAL] thread priority exceeds mutex priority ceiling.
[EINVAL] mutex is invalid.
[EDEADLK] calling thread already owns mutex. Hint: Always unlock within the same thread.
pthread_mutex_trylock
int pthread_mutex_trylock (
pthread_mutex_t *mutex);
Lock a mutex. If the mutex is currently locked, returns immediately with EBUSY. Otherwise, calling thread becomes owner until it unlocks.
References: 3.2,5.2.1 Headers: <pthread.h>
Errors: [EINVAL] thread priority exceeds mutex priority ceiling.
[EBUSY] mutex is already locked.
[EINVAL] mutex is invalid.
[EDEADLK] calling thread already owns mutex. Hint: Always unlock within the same thread.
pthread_mutex_unlock
int pthread_mutex_unlock (
pthread_mutex_t *mutex);
Unlock a mutex. The mutex becomes unowned. If any threads are waiting for the mutex, one is awakened (scheduling policy SCHED_FIFO and SCHED_RR policy waiters are chosen in priority order, then any others are chosen in unspecified order).
References: 3.2, 5.2.1
Headers: <pthread.h>
Errors: [EINVAL]mutex is invalid.
[EPERM] calling thread does not own mutex. Hint: Always unlock within the same thread.
9.3.5 Condition variables
Condition variables provide
pthread_condattr_destroy
int pthread_condattr_destroy (
pthread_condattr_t *attr);
Destroy a condition variable attributes object. The object can no longer be used.
References: 3.3, 5.2.2
Headers: <pthread.h>