## **Overview**
Provides process- and thread-related structures and functions.
**Since:**
1.0
**Version:**
1.0
## **Summary**
## Files
## Data Structures
Defines process scheduling parameters. |
## Functions
pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) | |
pthread_detach (pthread_t thread) | |
pthread_exit (void *retval) | Terminates the calling thread. |
pthread_join (pthread_t thread, void **retval) | Waits for a thread to terminate. |
pthread_self (void) | Obtains the ID of the calling thread. |
pthread_equal (pthread_t t1, pthread_t t2) | Compares whether two thread IDs are equal. |
pthread_setcancelstate (int state, int *oldstate) | Sets the cancelability state for the calling thread. |
pthread_setcanceltype (int type, int *oldtype) | Sets the cancelability type for the calling thread. |
pthread_testcancel (void) | Requests delivery of any pending cancellation request. |
pthread_cancel (pthread_t thread) | Sends a cancellation request to a thread. |
pthread_kill (pthread_t thread, int sig) | |
pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param) | Obtains the scheduling policy and parameters of a thread. |
pthread_setschedparam (pthread_t thread, int policy, const struct sched_param *param) | Sets a scheduling policy and parameters for a thread. |
pthread_setschedprio (pthread_t thread, int prio) | Sets a static scheduling priority for a thread. |
pthread_once (pthread_once_t *once_control, void(*init_routine)(void)) | Enables the initialization function to be called only once. |
pthread_mutex_init (pthread_mutex_t *__restrict m, const pthread_mutexattr_t *__restrict a) | |
pthread_mutex_lock (pthread_mutex_t *m) | |
pthread_mutex_unlock (pthread_mutex_t *m) | |
pthread_mutex_trylock (pthread_mutex_t *m) | |
pthread_mutex_timedlock (pthread_mutex_t *__restrict m, const struct timespec *__restrict at) | Blocks the calling thread to lock a mutex. |
pthread_mutex_destroy (pthread_mutex_t *m) | |
pthread_cond_init (pthread_cond_t *__restrict c, const pthread_condattr_t *__restrict a) | Initializes a condition variable. |
pthread_cond_destroy (pthread_cond_t *c) | Destroys a condition variable. |
pthread_cond_wait (pthread_cond_t *__restrict c, pthread_mutex_t *__restrict m) | Blocks the calling thread to wait for the condition set by pthread_con_signal(). |
pthread_cond_timedwait (pthread_cond_t *__restrict c, pthread_mutex_t *__restrict m, const struct timespec *__restrict ts) | Blocks the calling thread to wait for the condition set by pthread_con_signal() for a period of time specified by ts. |
pthread_cond_broadcast (pthread_cond_t *c) | Unblocks all threads that are currently blocked on the condition variable cond. |
pthread_cond_signal (pthread_cond_t *c) | |
pthread_rwlock_init (pthread_rwlock_t *__restrict rw, const pthread_rwlockattr_t *__restrict a) | Initializes a read-write lock. |
pthread_rwlock_destroy (pthread_rwlock_t *rw) | |
pthread_rwlock_rdlock (pthread_rwlock_t *rw) | Applies a read lock to a read-write lock. |
pthread_rwlock_tryrdlock (pthread_rwlock_t *rw) | Attempts to apply a read lock to a read-write lock. |
pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict rw, const struct timespec *__restrict at) | Blocks the calling thread to lock a read-write lock for reading. |
pthread_rwlock_wrlock (pthread_rwlock_t *rw) | Applies a write lock to a read-write lock. |
pthread_rwlock_trywrlock (pthread_rwlock_t *rw) | Attempts to apply a write lock to a read-write lock. |
pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict rw, const struct timespec *__restrict at) | Blocks the calling thread to lock a read-write lock for writing. |
pthread_rwlock_unlock (pthread_rwlock_t *rw) | |
pthread_spin_init (pthread_spinlock_t *s, int shared) | |
pthread_spin_destroy (pthread_spinlock_t *s) | |
pthread_spin_lock (pthread_spinlock_t *s) | |
pthread_spin_trylock (pthread_spinlock_t *s) | |
pthread_spin_unlock (pthread_spinlock_t *s) | |
pthread_barrier_init (pthread_barrier_t *__restrict b, const pthread_barrierattr_t *__restrict a, unsigned count) | |
pthread_barrier_destroy (pthread_barrier_t *b) | |
pthread_barrier_wait (pthread_barrier_t *b) | Synchronizes participating threads at a barrier. |
pthread_key_create (pthread_key_t *key, void(*destructor)(void *)) | Creates a key for thread data. |
pthread_key_delete (pthread_key_t key) | Deletes a key for thread data. |
pthread_getspecific (pthread_key_t key) | |
pthread_setspecific (pthread_key_t key, const void *value) | |
pthread_attr_init (pthread_attr_t *attr) | Initializes a thread attribute object. |
pthread_attr_destroy (pthread_attr_t *attr) | Destroys a thread attribute object. |
pthread_attr_getguardsize (const pthread_attr_t *attr, size_t *guardsize) | Obtains the guard size of a thread attribute object. |
pthread_attr_setguardsize (pthread_attr_t *attr, size_t guardsize) | Sets the guard size for a thread attribute object. |
pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize) | Obtains the stack size of a thread attribute object. |
pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize) | Sets the stack size for a thread attribute object. |
pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate) | Obtains the detach state of a thread attribute object. |
pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate) | Sets the detach state for a thread attribute object. |
pthread_attr_getstack (const pthread_attr_t *attr, void **stackaddr, size_t *stacksize) | Obtains stack attributes of a thread attribute object. |
pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, size_t stacksize) | Sets stack attributes for a thread attribute object. |
pthread_attr_getscope (const pthread_attr_t *arrt, int *scope) | Obtains contention scope attributes of a thread attribute object. |
pthread_attr_setscope (pthread_attr_t *arrt, int scope) | Sets contention scope attributes for a thread attribute object. |
pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *schedpolicy) | Obtains scheduling policy attributes of a thread attribute object. |
pthread_attr_setschedpolicy (pthread_attr_t *attr, int schedpolicy) | Sets scheduling policy attributes for a thread attribute object. |
pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *param) | Obtains scheduling parameter attributes of a thread attribute object. |
pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *param) | Sets scheduling parameter attributes for a thread attribute object. |
pthread_attr_getinheritsched (const pthread_attr_t *attr, int *inheritsched) | Obtains inherit scheduler attributes of a thread attribute object. |
pthread_attr_setinheritsched (pthread_attr_t *attr, int inheritsched) | Sets inherit scheduler attributes for a thread attribute object. |
pthread_mutexattr_destroy (pthread_mutexattr_t *attr) | Destroys a mutex attribute object. |
pthread_mutexattr_gettype (const pthread_mutexattr_t *__restrict attr, int *__restrict type) | Obtains the mutex type attribute. |
pthread_mutexattr_init (pthread_mutexattr_t *attr) | Initializes a mutex attribute object. |
pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type) | Sets the mutex type attribute. |
pthread_condattr_init (pthread_condattr_t *a) | Initializes a condition variable attribute object. |
pthread_condattr_destroy (pthread_condattr_t *a) | Destroys a condition variable attribute object. |
pthread_condattr_setclock (pthread_condattr_t *a, clockid_t clk) | Sets a clock for a condition variable attribute object. |
pthread_condattr_getclock (const pthread_condattr_t *__restrict a, clockid_t *__restrict clk) | Obtains the clock of a condition variable attribute object. |
pthread_rwlockattr_init (pthread_rwlockattr_t *attr) | Initializes a read-write lock attribute object. |
pthread_rwlockattr_destroy (pthread_rwlockattr_t *attr) | Destroys a read-write lock attribute object. |
pthread_barrierattr_destroy (pthread_barrierattr_t *a) | Destroys a barrier attribute object. |
pthread_barrierattr_init (pthread_barrierattr_t *a) | Initializes a barrier attribute object. |
pthread_atfork (void(*prepare)(void), void(*parent)(void), void(*child)(void)) | Registers a fork handler to be called before and after fork(). |
pthread_cleanup_push (void(*routine)(void *), void *arg) | Pushes the routine to the top of the clean-up handler stack. |
pthread_cleanup_pop (int execute) | Removes the routine at the top of the clean-up handler stack. |
pthread_getattr_np (pthread_t thread, pthread_attr_t *attr) | Obtains the attributes of a created thread. |
pthread_setname_np (pthread_t pthread, const char *name) | |
sched_get_priority_max (int policy) | Obtains the maximum static priority that can be used for a process. |
sched_get_priority_min (int policy) | Obtains the minimum static priority that can be used for a process. |
sched_getparam (pid_t pid, struct sched_param *param) | Obtains scheduling parameters of a process. |
sched_getscheduler (pid_t pid) | Obtains the scheduling policy of a process. |
sched_rr_get_interval (pid_t pid, struct timespec *interval) | Obtains the execution time limit of a process. |
sched_setparam (pid_t pid, const struct sched_param *param) | Sets scheduling parameters related to a scheduling policy for a process. |
sched_setscheduler (pid_t pid, int policy, const struct sched_param *param) | Sets a scheduling policy for a process. |
sched_yield (void) | |
capget (cap_user_header_t hdr_ptr, cap_user_data_t data_ptr) | Obtains the capability information of a specified process based on the input parameters (compatible with the Linux API format). |
capset (cap_user_header_t hdr_ptr, const cap_user_data_t data_ptr) | Sets the capability information for a specified process based on the input parameters (compatible with the Linux API format). |
ohos_capget (unsigned int *caps) | Obtains the capability information of a specified process based on the input parameters. |
ohos_capset (unsigned int caps) | Sets the capability information of a specified process based on the input parameters. |
getpriority (int which, id_t who) | Obtains the static priority of a specified ID. |
setpriority (int which, id_t who, int value) | Sets the static priority of a specified ID. |
wait (int *status) | Waits for any child process to end and reclaims its resources. |
waitpid (pid_t pid, int *status, int options) | Waits for a specified child process to end and reclaims its resources. |
## **Details**
## **Function Documentation**
## capget\(\)
```
int capget (cap_user_header_t hdr_ptr, cap_user_data_t data_ptr )
```
**Description:**
Obtains the capability information of a specified process based on the input parameters \(compatible with the Linux API format\).
**Parameters:**
**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.
## capset\(\)
```
int capset (cap_user_header_t hdr_ptr, const cap_user_data_t data_ptr )
```
**Description:**
Sets the capability information for a specified process based on the input parameters \(compatible with the Linux API format\).
**Parameters:**
**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the creation fails.
## getpriority\(\)
```
int getpriority (int which, id_t who )
```
**Description:**
Obtains the static priority of a specified ID.
**Parameters:**
which | Indicates a specified value. The values are as follows: |
who | Indicates the specified ID. |
**Returns:**
Returns the scheduling priority if the operation is successful; returns **-1** and sets **errno** to a value in the following table otherwise.
## ohos\_capget\(\)
```
int ohos_capget (unsigned int * caps)
```
**Description:**
Obtains the capability information of a specified process based on the input parameters.
**Parameters:**
caps | Indicates the pointer to the memory address for storing the obtained capability information of a specified process. |
**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.
## ohos\_capset\(\)
```
int ohos_capset (unsigned int caps)
```
**Description:**
Sets the capability information of a specified process based on the input parameters.
**Parameters:**
caps | Indicates the customized capability information of the process. Currently, the following capabilities are supported (other values do not take effect): OHOS_CAP_CHOWN: changes the permissions of file ownership. OHOS_CAP_DAC_EXECUTE: ignores discretionary access control (DAC) restrictions on file execution. OHOS_CAP_DAC_WRITE: ignores DAC restrictions on file write. OHOS_CAP_DAC_READ_SEARCH: ignores DAC restrictions on file read and search. OHOS_CAP_FOWNER: allows other users (not the file owner) to modify file permission configurations. OHOS_CAP_KILL: allows the current process to send signals to other processes with different UIDs. OHOS_CAP_SETGID: allows changing the group ID of the process. OHOS_CAP_SETUID: allows changing the user ID of the process. OHOS_CAP_NET_BIND_SERVICE: allows the process to be bound to a port whose number is smaller than 1024. OHOS_CAP_NET_BROADCAST: allows network broadcast and multicast. OHOS_CAP_NET_ADMIN: allows network-related management functions. OHOS_CAP_NET_RAW: allows raw sockets to be used. OHOS_CAP_FS_MOUNT: allows mounting operations. OHOS_CAP_FS_FORMAT: allows storage formatting operations. OHOS_CAP_SCHED_SETPRIORITY: allows priority increase and priority setting for other processes. OHOS_CAP_SET_TIMEOFDAY: allows calling of the timeofday API. OHOS_CAP_CLOCK_SETTIME: allows calling of the clock_settime API. OHOS_CAP_CAPSET: allows changing the capabilities. OHOS_CAP_SHELL_EXEC: allows calling of the shellexec API. |
**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the creation fails.
## pthread\_atfork\(\)
```
int pthread_atfork (void(*)(void) prepare, void(*)(void) parent, void(*)(void) child )
```
**Description:**
Registers a fork handler to be called before and after [fork\(\)](UTILS.md#gaa4e4714e6e8927c80b2553a40094b6d9).
**Parameters:**
prepare | Indicates the pointer to the fork handler to be called before fork(). |
parent | Indicates the pointer to the fork handler to be called after fork() in the parent process. |
child | Indicates the pointer to the fork handler to be called after fork() in the child process. |
**Returns:**
Returns **0** if the operation is successful; returns **-1** otherwise.
## pthread\_attr\_destroy\(\)
```
int pthread_attr_destroy (pthread_attr_t * attr)
```
**Description:**
Destroys a thread attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the thread attribute object to destroy. |
**Returns:**
Returns **0**.
## pthread\_attr\_getdetachstate\(\)
```
int pthread_attr_getdetachstate (const pthread_attr_t * attr, int * detachstate )
```
**Description:**
Obtains the detach state of a thread attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
detachstate | Indicates the pointer to the obtained detach state. |
**Returns:**
Returns **0**.
## pthread\_attr\_getguardsize\(\)
```
int pthread_attr_getguardsize (const pthread_attr_t * attr, size_t * guardsize )
```
**Description:**
Obtains the guard size of a thread attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
guardsize | Indicates the pointer to the obtained guard size. |
**Returns:**
Returns **0**.
## pthread\_attr\_getinheritsched\(\)
```
int pthread_attr_getinheritsched (const pthread_attr_t * attr, int * inheritsched )
```
**Description:**
Obtains inherit scheduler attributes of a thread attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
inheritsched | Indicates the pointer to the obtained inherit scheduler attributes. |
**Returns:**
Returns **0**.
## pthread\_attr\_getschedparam\(\)
```
int pthread_attr_getschedparam (const pthread_attr_t * attr, struct [sched_param](sched_param.md) * param )
```
**Description:**
Obtains scheduling parameter attributes of a thread attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
param | Indicates the pointer to the obtained scheduling parameter attributes. Only the thread priority is supported. The priority ranges from 0 (highest priority) to 31 (lowest priority). |
**Returns:**
Returns **0**.
## pthread\_attr\_getschedpolicy\(\)
```
int pthread_attr_getschedpolicy (const pthread_attr_t * attr, int * schedpolicy )
```
**Description:**
Obtains scheduling policy attributes of a thread attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
schedpolicy | Indicates the pointer to the obtained scheduling policy attributes. Only SCHED_FIFO and SCHED_RR are supported. |
**Returns:**
Returns **0**.
## pthread\_attr\_getscope\(\)
```
int pthread_attr_getscope (const pthread_attr_t * arrt, int * scope )
```
**Description:**
Obtains contention scope attributes of a thread attribute object.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
scope | Indicates the pointer to the start address of the buffer that stores the target thread attribute object. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_attr\_getstack\(\)
```
int pthread_attr_getstack (const pthread_attr_t * attr, void ** stackaddr, size_t * stacksize )
```
**Description:**
Obtains stack attributes of a thread attribute object.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
stackaddr | Indicates the double pointer to the start address of the buffer that stores the obtained stack attributes. |
stacksize | Indicates the pointer to the size of the buffer that stores the obtained stack attributes. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_attr\_getstacksize\(\)
```
int pthread_attr_getstacksize (const pthread_attr_t * attr, size_t * stacksize )
```
**Description:**
Obtains the stack size of a thread attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
stacksize | Indicates the pointer to the obtained stack size. |
**Returns:**
Returns **0**.
## pthread\_attr\_init\(\)
```
int pthread_attr_init (pthread_attr_t * attr)
```
**Description:**
Initializes a thread attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the thread attribute object that is successfully initialized. |
**Returns:**
Returns **0**.
## pthread\_attr\_setdetachstate\(\)
```
int pthread_attr_setdetachstate (pthread_attr_t * attr, int detachstate )
```
**Description:**
Sets the detach state for a thread attribute object.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
detachstate | Indicates the detach state to set. Available values are as follows: |
Threads using attr are created in the detached state. | |
Threads using attr are created in the joinable state. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_attr\_setguardsize\(\)
```
int pthread_attr_setguardsize (pthread_attr_t * attr, size_t guardsize )
```
**Description:**
Sets the guard size for a thread attribute object.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
guardsize | Indicates the guard size to set. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_attr\_setinheritsched\(\)
```
int pthread_attr_setinheritsched (pthread_attr_t * attr, int inheritsched )
```
**Description:**
Sets inherit scheduler attributes for a thread attribute object.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
inheritsched | Indicates the inherit scheduler attributes to set. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
Invalid inherit scheduler attribute. |
## pthread\_attr\_setschedparam\(\)
```
int pthread_attr_setschedparam (pthread_attr_t * attr, const struct [sched_param](sched_param.md) * param )
```
**Description:**
Sets scheduling parameter attributes for a thread attribute object.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
param | Indicates the pointer to the scheduling parameter attributes to set. Only the thread priority is supported. The priority ranges from 0 (highest priority) to 31 (lowest priority). |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
Invalid scheduling parameter attributes. |
## pthread\_attr\_setschedpolicy\(\)
```
int pthread_attr_setschedpolicy (pthread_attr_t * attr, int schedpolicy )
```
**Description:**
Sets scheduling policy attributes for a thread attribute object.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
schedpolicy | Indicates the scheduling policy attributes to set. Only SCHED_FIFO and SCHED_RR are supported. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
Invalid scheduling policy attribute. |
## pthread\_attr\_setscope\(\)
```
int pthread_attr_setscope (pthread_attr_t * arrt, int scope )
```
**Description:**
Sets contention scope attributes for a thread attribute object.
The contention scope attribute defines a set of threads against which a thread competes for resources such as the CPU. POSIX.1-2001 specifies two values for **scope**:
POSIX.1-2001 does not specify how these threads contend with other threads in other process on the system or with other threads in the same process that were created with the **PTHREAD\_SCOPE\_SYSTEM** contention scope.
**Parameters:**
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_attr\_setstack\(\)
```
int pthread_attr_setstack (pthread_attr_t * attr, void * stackaddr, size_t stacksize )
```
**Description:**
Sets stack attributes for a thread attribute object.
**Parameters:**
attr | Indicates the pointer to the thread attribute object. |
stackaddr | Indicates the pointer to the start address of the buffer that stores the stack attributes to set. |
stacksize | Indicates the size of the buffer that stores the stack attributes to set. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_attr\_setstacksize\(\)
```
int pthread_attr_setstacksize (pthread_attr_t * attr, size_t stacksize )
```
**Description:**
Sets the stack size for a thread attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the target thread attribute object. |
stacksize | Indicates the stack size. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_barrier\_destroy\(\)
```
int pthread_barrier_destroy (pthread_barrier_t * b)
```
**Description:**
Destroys a barrier.
This function always succeeds.
**Parameters:**
b | Indicates the pointer to the barrier to destroy. |
**Returns:**
Returns **0**.
## pthread\_barrier\_init\(\)
```
int pthread_barrier_init (pthread_barrier_t *__restrict b, const pthread_barrierattr_t *__restrict a, unsigned count )
```
**Description:**
Initializes a barrier.
**Parameters:**
b | Indicates the pointer to the barrier to initialize. |
a | Indicates the pointer to the barrier attribute object. If this parameter is set to NULL, the default barrier attributes are used. |
count | Indicates the number of threads that must call pthread_barrier_wait() before any of them successfully returns from the call. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The value of count is greater than the maximum number of threads to block. |
## pthread\_barrier\_wait\(\)
```
int pthread_barrier_wait (pthread_barrier_t * b)
```
**Description:**
Synchronizes participating threads at a barrier.
The call is blocked until the required number of threads have called this function with the specified barrier.
**Parameters:**
b | Indicates the pointer to the barrier to be used for synchronization. |
**Returns:**
Returns **PTHREAD\_BARRIER\_SERIAL\_THREAD** for the first restored thread and **0** for other threads.
## pthread\_barrierattr\_destroy\(\)
```
int pthread_barrierattr_destroy (pthread_barrierattr_t * a)
```
**Description:**
Destroys a barrier attribute object.
This function always succeeds.
**Parameters:**
a | Indicates the pointer to the barrier attribute object to destroy. |
**Returns:**
Returns **0**.
## pthread\_barrierattr\_init\(\)
```
int pthread_barrierattr_init (pthread_barrierattr_t * a)
```
**Description:**
Initializes a barrier attribute object.
This function always succeeds.
**Parameters:**
a | Indicates the pointer to the barrier attribute object to initialize. |
**Returns:**
Returns **0**.
## pthread\_cancel\(\)
```
int pthread_cancel (pthread_t thread)
```
**Description:**
Sends a cancellation request to a thread.
**Parameters:**
thread | Indicates the thread to receive the cancellation request. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_cleanup\_pop\(\)
```
void pthread_cleanup_pop (int execute)
```
**Description:**
Removes the routine at the top of the clean-up handler stack.
**Parameters:**
execute | Specifies whether the routine at the top of the clean-up handler stack should be executed. If this parameter is set to a non-zero value, the routine at the top of the clean-up handler stack must be popped and executed. |
## pthread\_cleanup\_push\(\)
```
void pthread_cleanup_push (void(*)(void *) routine, void * arg )
```
**Description:**
Pushes the routine to the top of the clean-up handler stack.
**Parameters:**
routine | Indicates the pointer to the routine used to complete the clean-up. |
arg | Indicates the parameter to be passed to the routine. |
## pthread\_cond\_broadcast\(\)
```
int pthread_cond_broadcast (pthread_cond_t * c)
```
**Description:**
Unblocks all threads that are currently blocked on the condition variable **cond**.
This function always succeeds.
**Parameters:**
c | Indicates the pointer to the condition variable to broadcast. |
**Returns:**
Returns **0**.
## pthread\_cond\_destroy\(\)
```
int pthread_cond_destroy (pthread_cond_t * c)
```
**Description:**
Destroys a condition variable.
This function always succeeds.
**Parameters:**
c | Indicates the pointer to the condition variable to destroy. |
**Returns:**
Returns **0**.
## pthread\_cond\_init\(\)
```
int pthread_cond_init (pthread_cond_t *__restrict c, const pthread_condattr_t *__restrict a )
```
**Description:**
Initializes a condition variable.
This function always succeeds.
**Parameters:**
**Returns:**
Returns **0**.
## pthread\_cond\_signal\(\)
```
int pthread_cond_signal (pthread_cond_t * c)
```
**Description:**
Unblocks a thread.
If multiple threads are blocked on the condition variable **cond**, this function unblocks at least one thread. This function always succeeds.
**Parameters:**
c | Indicates the pointer to the condition variable to signal. |
**Returns:**
Returns **0**.
## pthread\_cond\_timedwait\(\)
```
int pthread_cond_timedwait (pthread_cond_t *__restrict c, pthread_mutex_t *__restrict m, const struct [timespec](timespec.md) *__restrict ts )
```
**Description:**
Blocks the calling thread to wait for the condition set by **pthread\_con\_signal\(\)** for a period of time specified by **ts**.
**Parameters:**
c | Indicates the pointer to the condition variable to wait for. |
m | Indicates the pointer to the mutex associated with the condition variable. |
ts | Indicates the pointer to the absolute system time when the calling thread stops blocking. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The associated mutex is invalid. |
## pthread\_cond\_wait\(\)
```
int pthread_cond_wait (pthread_cond_t *__restrict c, pthread_mutex_t *__restrict m )
```
**Description:**
Blocks the calling thread to wait for the condition set by **pthread\_con\_signal\(\)**.
**Parameters:**
c | Indicates the pointer to the condition variable to wait for. |
m | Indicates the pointer to the mutex associated with the condition variable. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The associated mutex is invalid. |
## pthread\_condattr\_destroy\(\)
```
int pthread_condattr_destroy (pthread_condattr_t * a)
```
**Description:**
Destroys a condition variable attribute object.
This function always succeeds.
**Parameters:**
a | Indicates the pointer to the variable that contains the condition variable attributes. |
**Returns:**
Returns **0**.
## pthread\_condattr\_getclock\(\)
```
int pthread_condattr_getclock (const pthread_condattr_t *__restrict a, clockid_t *__restrict clk )
```
**Description:**
Obtains the clock of a condition variable attribute object.
This function always succeeds.
**Parameters:**
a | Indicates the pointer to the variable that contains the condition variable attributes. |
clk | Indicates the pointer to the obtained clock ID. |
**Returns:**
Returns **0**.
## pthread\_condattr\_init\(\)
```
int pthread_condattr_init (pthread_condattr_t * a)
```
**Description:**
Initializes a condition variable attribute object.
This function always succeeds.
**Parameters:**
a | Indicates the pointer to the variable that contains the condition variable attributes. |
**Returns:**
Returns **0**.
## pthread\_condattr\_setclock\(\)
```
int pthread_condattr_setclock (pthread_condattr_t * a, clockid_t clk )
```
**Description:**
Sets a clock for a condition variable attribute object.
**Parameters:**
a | Indicates the pointer to the variable that contains the condition variable attributes. |
clk | Indicates the ID of the clock to set. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_create\(\)
```
int pthread_create (pthread_t * thread, const pthread_attr_t * attr, void *(*)(void *) start_routine, void * arg )
```
**Description:**
Creates a thread.
This function creates a thread in the calling process. The new thread starts execution from the entry point **star\_routine**. **arg** is passed as the unique argument of the entry point.
**Parameters:**
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
Insufficient resource, or the maximum number of threads allowed by the system reached. | |
## pthread\_detach\(\)
```
int pthread_detach (pthread_t thread)
```
**Description:**
Detaches a thread.
**Parameters:**
thread | Indicates the ID of the user-level thread to detach. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_equal\(\)
```
int pthread_equal (pthread_t t1, pthread_t t2 )
```
**Description:**
Compares whether two thread IDs are equal.
**Parameters:**
t1 | Indicates the first thread. |
t2 | Indicates the second thread. |
**Returns:**
Returns **0** if the two are not equal; returns a non-zero value otherwise.
## pthread\_exit\(\)
```
_Noreturn void pthread_exit (void * retval)
```
**Description:**
Terminates the calling thread.
**Parameters:**
retval | Indicates the pointer to the return value after the thread is terminated. |
## pthread\_getattr\_np\(\)
```
int pthread_getattr_np (pthread_t thread, pthread_attr_t * attr )
```
**Description:**
Obtains the attributes of a created thread.
This function always succeeds.
**Parameters:**
thread | Indicates the thread that has been created. |
attr | Indicates the pointer to the attribute values that describe the running thread. |
**Returns:**
Returns **0**.
## pthread\_getschedparam\(\)
```
int pthread_getschedparam (pthread_t thread, int * policy, struct [sched_param](sched_param.md) * param )
```
**Description:**
Obtains the scheduling policy and parameters of a thread.
**Parameters:**
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
No permission to obtain the specified scheduling policy and parameters. |
## pthread\_getspecific\(\)
```
void* pthread_getspecific (pthread_key_t key)
```
**Description:**
Obtains specific thread data.
**Parameters:**
key | Indicates the key bound to the thread data. |
## pthread\_join\(\)
```
int pthread_join (pthread_t thread, void ** retval )
```
**Description:**
Waits for a thread to terminate.
This function returns a value immediately if the thread has already terminated.
**Parameters:**
thread | Indicates the target thread. |
retval | Indicates the double pointer to the exit or cancellation status of the target thread. This parameter can be NULL. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The thread is not joinable, or the target thread is the calling thread. |
## pthread\_key\_create\(\)
```
int pthread_key_create (pthread_key_t * key, void(*)(void *) destructor )
```
**Description:**
Creates a key for thread data.
**Parameters:**
key | Indicates the pointer to the key to set for the thread data. |
destructor | Indicates the pointer to the function to be bound to the key. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The system lacks the necessary resources to create another thread-specific key, or the number of keys exceeds the limit specified by PTHREAD_KEYS_MAX for each process. |
## pthread\_key\_delete\(\)
```
int pthread_key_delete (pthread_key_t key)
```
**Description:**
Deletes a key for thread data.
**Parameters:**
key | Indicates the pointer to the key to delete for the thread data. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_kill\(\)
```
int pthread_kill (pthread_t thread, int sig )
```
**Description:**
Sends a signal to a thread.
If **sig** is **0**, no signal is sent, but error checking is still performed. Therefore, you can call this function with **sig** set to **0** to check whether a thread exists.
**Parameters:**
thread | Indicates the thread to receive the signal. |
sig | Indicates the signal to send. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_mutex\_destroy\(\)
```
int pthread_mutex_destroy (pthread_mutex_t * m)
```
**Description:**
Destroys a mutex.
This function always succeeds.
**Parameters:**
m | Indicates the pointer to the mutex to destroy. |
**Returns:**
Returns **0**.
## pthread\_mutex\_init\(\)
```
int pthread_mutex_init (pthread_mutex_t *__restrict m, const pthread_mutexattr_t *__restrict a )
```
**Description:**
Initializes a mutex.
This function dynamically creates a mutex. The parameter **a** specifies the attributes of the mutex. This function always succeeds.
**Parameters:**
**Returns:**
Returns **0**.
## pthread\_mutex\_lock\(\)
```
int pthread_mutex_lock (pthread_mutex_t * m)
```
**Description:**
Locks a mutex.
If the mutex is already locked by a thread, the call is blocked until the holding thread unlocks the mutex by calling [pthread\_mutex\_unlock\(\)](PROCESS.md#ga02a3c64dac70730e226c31c0e7dbb45c).
**Parameters:**
m | Indicates the pointer to the mutex to lock. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_mutex\_timedlock\(\)
```
int pthread_mutex_timedlock (pthread_mutex_t *__restrict m, const struct [timespec](timespec.md) *__restrict at )
```
**Description:**
Blocks the calling thread to lock a mutex.
If the mutex is already locked, the call is blocked until the specified timeout duration expires or the holding thread unlocks the mutex by calling [pthread\_mutex\_unlock\(\)](PROCESS.md#ga02a3c64dac70730e226c31c0e7dbb45c).
**Parameters:**
m | Indicates the pointer to the mutex to lock. |
at | Indicates the pointer to the maximum duration that the calling thread waits for the mutex. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The mutex has been damaged during the waiting. | |
The maximum number of recursive locks for the mutex has been exceeded. | |
The mutex cannot be acquired within the specified period of time. |
## pthread\_mutex\_trylock\(\)
```
int pthread_mutex_trylock (pthread_mutex_t * m)
```
**Description:**
Attempts to lock a mutex.
This function attempts to acquire a mutex, without blocking the calling thread. If the mutex is already locked, the error code **EBUSY** is returned immediately.
**Parameters:**
m | Indicates the pointer to the mutex to lock. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The mutex has been damaged during the waiting. | |
The maximum number of recursive locks for the mutex has been exceeded. |
## pthread\_mutex\_unlock\(\)
```
int pthread_mutex_unlock (pthread_mutex_t * m)
```
**Description:**
Unlocks a mutex.
If the calling thread attempts to unlock a mutex that it has not locked \(by calling [pthread\_mutex\_lock\(\)](PROCESS.md#gafd70d6f2c50e22b996c926fb9d6ad291), [pthread\_mutex\_trylock\(\)](PROCESS.md#gacc1ccbaf3d76572da85a8030bba1ede4), or **pthread\_mutex\_timedlock\_np\(\)**, the unlock request fails and the error code **EPERM** is returned.
**Parameters:**
m | Indicates the pointer to the mutex to unlock. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The mutex has not been locked by the calling thread. |
## pthread\_mutexattr\_destroy\(\)
```
int pthread_mutexattr_destroy (pthread_mutexattr_t * attr)
```
**Description:**
Destroys a mutex attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the target mutex attribute object. |
**Returns:**
Returns **0**.
## pthread\_mutexattr\_gettype\(\)
```
int pthread_mutexattr_gettype (const pthread_mutexattr_t *__restrict attr, int *__restrict type )
```
**Description:**
Obtains the mutex type attribute.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the mutex attribute object. |
type | Indicates the pointer to the obtained mutex type attribute. |
**Returns:**
Returns **0**.
## pthread\_mutexattr\_init\(\)
```
int pthread_mutexattr_init (pthread_mutexattr_t * attr)
```
**Description:**
Initializes a mutex attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the target mutex attribute object. |
**Returns:**
Returns **0**.
## pthread\_mutexattr\_settype\(\)
```
int pthread_mutexattr_settype (pthread_mutexattr_t * attr, int type )
```
**Description:**
Sets the mutex type attribute.
**Parameters:**
attr | Indicates the pointer to the mutex attribute object. |
type | Indicates the type of the mutex. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_once\(\)
```
int pthread_once (pthread_once_t * once_control, void(*)(void) init_routine )
```
**Description:**
Enables the initialization function to be called only once.
This function dynamically initializes the function specified by **init\_routine** and ensures that it will be called only once.
**Parameters:**
**Returns:**
Returns **0** if **once\_control** is set to **0** or **2**. If **once\_control** is **1**, the calling thread waits until the other thread completes initialization.
## pthread\_rwlock\_destroy\(\)
```
int pthread_rwlock_destroy (pthread_rwlock_t * rw)
```
**Description:**
Destroys a read-write lock.
This function always succeeds.
**Parameters:**
rw | Indicates the pointer to the read-write lock to destroy. |
**Returns:**
Returns **0**.
## pthread\_rwlock\_init\(\)
```
int pthread_rwlock_init (pthread_rwlock_t *__restrict rw, const pthread_rwlockattr_t *__restrict a )
```
**Description:**
Initializes a read-write lock.
This function always succeeds.
**Parameters:**
**Returns:**
Returns **0**.
## pthread\_rwlock\_rdlock\(\)
```
int pthread_rwlock_rdlock (pthread_rwlock_t * rw)
```
**Description:**
Applies a read lock to a read-write lock.
**Parameters:**
rw | Indicates the pointer to the target read-write lock. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The read-write lock has been damaged during the waiting. |
## pthread\_rwlock\_timedrdlock\(\)
```
int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict rw, const struct [timespec](timespec.md) *__restrict at )
```
**Description:**
Blocks the calling thread to lock a read-write lock for reading.
If the read-write lock is already locked, the calling thread is blocked until the specified timeout duration expires or the holding thread unlocks the read-write lock by calling [pthread\_rwlock\_unlock\(\)](PROCESS.md#gaffd8a19e83fc87d865d103d6fbce8c4f).
**Parameters:**
rw | Indicates the pointer to the read-write lock to lock. |
at | Indicates the maximum duration that the calling thread waits for the read-write lock. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The read-write lock has been damaged during the waiting. | |
The read-write lock is already locked. | |
The read-write lock cannot be acquired within the specified period of time. |
## pthread\_rwlock\_timedwrlock\(\)
```
int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict rw, const struct [timespec](timespec.md) *__restrict at )
```
**Description:**
Blocks the calling thread to lock a read-write lock for writing.
If the read-write lock is already locked, the calling thread is blocked until the specified timeout duration expires or the holding thread unlocks the read-write lock by calling [pthread\_rwlock\_unlock\(\)](PROCESS.md#gaffd8a19e83fc87d865d103d6fbce8c4f).
**Parameters:**
rw | Indicates the pointer to the read-write lock to lock. |
at | Indicates the pointer to the maximum duration that the calling thread waits for the read-write lock. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The read-write lock has been damaged during the waiting. | |
The read-write lock is already locked. | |
The read-write lock cannot be acquired within the specified period of time. |
## pthread\_rwlock\_tryrdlock\(\)
```
int pthread_rwlock_tryrdlock (pthread_rwlock_t * rw)
```
**Description:**
Attempts to apply a read lock to a read-write lock.
This function attempts to lock a read-write lock for reading, without blocking the calling thread. If the read-write lock is already locked, the error code **EBUSY** is returned immediately.
**Parameters:**
rw | Indicates the pointer to the target read-write lock. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The read-write lock has been damaged during the waiting. | |
The read-write lock is already locked. |
## pthread\_rwlock\_trywrlock\(\)
```
int pthread_rwlock_trywrlock (pthread_rwlock_t * rw)
```
**Description:**
Attempts to apply a write lock to a read-write lock.
This function attempts to lock a read-write lock for writing, without blocking the calling thread. If the read-write lock is already locked, the error code **EBUSY** is returned immediately.
**Parameters:**
rw | Indicates the pointer to the read-write lock to lock. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The read-write lock has been damaged during the waiting. | |
The read-write lock is already locked. |
## pthread\_rwlock\_unlock\(\)
```
int pthread_rwlock_unlock (pthread_rwlock_t * rw)
```
**Description:**
Unlocks a read-write lock.
If the calling thread attempts to unlock a read-write lock that it has not locked, the unlock request fails and the error code **EPERM** is returned.
**Parameters:**
rw | Indicates the pointer to the read-write lock to unlock. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The read-write lock is not held by the calling thread. |
## pthread\_rwlock\_wrlock\(\)
```
int pthread_rwlock_wrlock (pthread_rwlock_t * rw)
```
**Description:**
Applies a write lock to a read-write lock.
**Parameters:**
rw | Indicates the pointer to the read-write lock to lock. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The read-write lock has been damaged during the waiting. | |
The read-write lock is already locked. |
## pthread\_rwlockattr\_destroy\(\)
```
int pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr)
```
**Description:**
Destroys a read-write lock attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the read-write lock attribute object to destroy. |
**Returns:**
Returns **0**.
## pthread\_rwlockattr\_init\(\)
```
int pthread_rwlockattr_init (pthread_rwlockattr_t * attr)
```
**Description:**
Initializes a read-write lock attribute object.
This function always succeeds.
**Parameters:**
attr | Indicates the pointer to the read-write lock attribute object to initialize. |
**Returns:**
Returns **0**.
## pthread\_self\(\)
```
pthread_t pthread_self (void )
```
**Description:**
Obtains the ID of the calling thread.
This function always succeeds.
**Returns:**
Returns the thread ID.
## pthread\_setcancelstate\(\)
```
int pthread_setcancelstate (int state, int * oldstate )
```
**Description:**
Sets the cancelability state for the calling thread.
This function sets the cancelability state of the calling thread to the value specified by **state**. The previous cancelability state is stored in the buffer pointed to by oldstate.
**Parameters:**
state | Indicates the cancelability state to set. Available values are as follows: |
oldstate | Indicates the pointer to the previous cancelability state before the setting. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_setcanceltype\(\)
```
int pthread_setcanceltype (int type, int * oldtype )
```
**Description:**
Sets the cancelability type for the calling thread.
This function sets the cancelability type of the calling thread to the value specified by **type**. The previous cancelability type is stored in the buffer pointed to by oldtype.
**Parameters:**
type | Indicates the cancelability type to set. Available values are as follows: |
oldtype | Indicates the pointer to the previous cancelability type before the setting. |
The thread is canceled until the next cancellation point. | |
The thread is canceled immediately upon receiving a cancellation request. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
## pthread\_setname\_np\(\)
```
int pthread_setname_np (pthread_t pthread, const char * name )
```
**Description:**
Sets the thread name.
**Parameters:**
thread | Indicates the thread whose name is to be changed. |
name | Indicates the pointer to the thread name to set. The value contains a maximum of 16 characters, including the terminating null byte ('\0'). |
**Attention:**
Currently, a thread can change its own thread name only.
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
Failed to copy data from the user-level thread. |
## pthread\_setschedparam\(\)
```
int pthread_setschedparam (pthread_t thread, int policy, const struct [sched_param](sched_param.md) * param )
```
**Description:**
Sets a scheduling policy and parameters for a thread.
**Parameters:**
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise. If the operation fails, the scheduling policy and parameters of the target thread remain unchanged.
No permission to set the specified scheduling policy and parameters. |
## pthread\_setschedprio\(\)
```
int pthread_setschedprio (pthread_t thread, int prio )
```
**Description:**
Sets a static scheduling priority for a thread.
**Parameters:**
thread | Indicates the target thread. |
priority | Indicates the static scheduling priority to set. The value ranges from 0 (highest priority) to 31 (lowest priority). |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise. If the operation fails, the scheduling policy of the target thread remains unchanged.
No permission to set the specified scheduling policy and parameters. |
## pthread\_setspecific\(\)
```
int pthread_setspecific (pthread_key_t key, const void * value )
```
**Description:**
Sets specific thread data.
This function always succeeds.
**Parameters:**
key | Indicates the key bound to the thread data. |
value | Indicates the pointer to the thread data to be bound to the key. |
**Returns:**
Returns **0**.
## pthread\_spin\_destroy\(\)
```
int pthread_spin_destroy (pthread_spinlock_t * s)
```
**Description:**
Destroys a spin lock.
This function always succeeds.
**Parameters:**
s | Indicates the pointer to the spin lock to destroy. |
**Returns:**
Returns **0**.
## pthread\_spin\_init\(\)
```
int pthread_spin_init (pthread_spinlock_t * s, int shared )
```
**Description:**
Initializes a spin lock.
This function always succeeds.
**Parameters:**
s | Indicates the pointer to the spin lock to initialize. |
shared | Indicates thread process-shared synchronization, which is not supported. |
**Returns:**
Returns **0**.
## pthread\_spin\_lock\(\)
```
int pthread_spin_lock (pthread_spinlock_t * s)
```
**Description:**
Locks a spin lock.
This function always succeeds.
**Parameters:**
s | Indicates the pointer to the spin lock to lock. |
**Returns:**
Returns **0**.
## pthread\_spin\_trylock\(\)
```
int pthread_spin_trylock (pthread_spinlock_t * s)
```
**Description:**
Attempts to lock a spin lock.
This function attempts to lock the spin lock, without blocking the calling thread. If the spin lock is already locked, the error code **EBUSY** is returned immediately.
**Parameters:**
s | Indicates the pointer to the spin lock to lock. |
**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.
The spin lock has been held by another thread. |
## pthread\_spin\_unlock\(\)
```
int pthread_spin_unlock (pthread_spinlock_t * s)
```
**Description:**
Unlocks a spin lock.
This function always succeeds.
**Parameters:**
s | Indicates the pointer to the spin lock to unlock. |
**Returns:**
Returns **0**.
## pthread\_testcancel\(\)
```
void pthread_testcancel (void )
```
**Description:**
Requests delivery of any pending cancellation request.
This function creates a cancellation point in the calling thread. In this way, the thread executing code that contains no cancellation point responds to the cancellation request. This function always succeeds.
**Returns:**
Returns the cancellation point.
## sched\_get\_priority\_max\(\)
```
int sched_get_priority_max (int policy)
```
**Description:**
Obtains the maximum static priority that can be used for a process.
This function returns the lowest priority of process scheduling in a scheduling policy specified by **policy**. The value of **policy** must be a value defined in [sched.h](sched-h.md).
**Parameters:**
policy | Indicates the scheduling policy. The value can be SCHED_FIFO or SCHED_RR, but not SCHED_OTHER, SCHED_BATCH, SCHED_IDLE, or SCHED_DEADLINE. |
**Returns:**
Returns the lowest priority of the scheduling policy if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.
Invalid parameter. The value of policy is not a defined scheduling policy. | |
Unsupported scheduling policy. |
## sched\_get\_priority\_min\(\)
```
int sched_get_priority_min (int policy)
```
**Description:**
Obtains the minimum static priority that can be used for a process.
This function returns the highest priority of process scheduling in a scheduling policy specified by **policy**. The value of **policy** must be a value defined in [sched.h](sched-h.md).
**Parameters:**
policy | Indicates the scheduling policy. The value can be SCHED_FIFO or SCHED_RR, but not SCHED_OTHER, SCHED_BATCH, SCHED_IDLE, or SCHED_DEADLINE. |
**Returns:**
Returns the highest priority of the scheduling policy if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.
Invalid parameter. The value of policy is not a defined scheduling policy. | |
Unsupported scheduling policy. |
## sched\_getparam\(\)
```
int sched_getparam (pid_t pid, struct [sched_param](sched_param.md) * param )
```
**Description:**
Obtains scheduling parameters of a process.
**Parameters:**
**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.
The process specified by pid cannot be found. |
## sched\_getscheduler\(\)
```
int sched_getscheduler (pid_t pid)
```
**Description:**
Obtains the scheduling policy of a process.
**Parameters:**
pid | Indicates the ID of the process for which the scheduling policy is to be obtained. If this parameter is set to 0, the scheduling policy of the calling process is to be obtained. |
**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.
The process specified by pid cannot be found. |
## sched\_rr\_get\_interval\(\)
```
int sched_rr_get_interval (pid_t pid, struct [timespec](timespec.md) * interval )
```
**Description:**
Obtains the execution time limit of a process.
This function updates the **timespec** structure referenced by the parameter **interval** to record the execution time limit of a process.
**Parameters:**
**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.
An error occurred when copying information to the user space. | |
The process specified by pid cannot be found. |
## sched\_setparam\(\)
```
int sched_setparam (pid_t pid, const struct [sched_param](sched_param.md) * param )
```
**Description:**
Sets scheduling parameters related to a scheduling policy for a process.
**Parameters:**
**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.
The process specified by pid cannot be found. |
## sched\_setscheduler\(\)
```
int sched_setscheduler (pid_t pid, int policy, const struct [sched_param](sched_param.md) * param )
```
**Description:**
Sets a scheduling policy for a process.
**Parameters:**
**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.
The process specified by pid cannot be found. |
## sched\_yield\(\)
```
int sched_yield (void )
```
**Description:**
Yields the running process.
**Returns:**
Returns **0** if the operation is successful; returns **-1** otherwise.
## setpriority\(\)
```
int setpriority (int which, id_t who, int value )
```
**Description:**
Sets the static priority of a specified ID.
**Parameters:**
which | Indicates a specified value. The values are as follows: |
who | Indicates the specified ID. |
value | Indicates the target priority to set. |
**Returns:**
Returns the scheduling priority if the operation is successful; returns **-1** and sets **errno** to a value in the following table otherwise.
## wait\(\)
```
pid_t wait (int * status)
```
**Description:**
Waits for any child process to end and reclaims its resources.
**Parameters:**
status | Indicates the pointer to the obtained status information. If this parameter is not NULL, the status information is stored in the int value that it points to. You can use the following macros defined in private.h to check the integer (the macro uses the integer as a parameter instead of the pointer that points to it):
|
**Returns:**
Returns the child process ID if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.
The child process does not exist, or the specified process group does not exist. | |
The child process ends abnormally. |
## waitpid\(\)
```
pid_t waitpid (pid_t pid, int * status, int options )
```
**Description:**
Waits for a specified child process to end and reclaims its resources.
**Parameters:**
pid | Indicates the ID of the child process to wait for.
|
status | Indicates the pointer to the obtained status information. If this parameter is not NULL, the status information is stored in the int value that it points to. You can use the following macros defined in private.h to check the integer (the macro uses the integer as a parameter instead of the pointer that points to it):
WIFSIGNALED, WIFSTOPPED, WSTOPSIG, WCOREDUMP, WIFCONTINUED, and WUNTRACED are not supported. |
options | Provides some options to control the behavior of this function. If you do not want to use these options, set this parameter to 0. WNOHANG: If the child process specified by pid is not ended, this function returns 0 immediately instead of blocking the calling process. If the child process is ended, the process ID of the child process is returned. WUNTRACED, WEXITED, WSTOPPED, WCONTINUED, and WNOWAIT are not supported. |
**Returns:**
Returns the child process ID if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.
The child process does not exist, or the specified process group does not exist. | |
The child process ends abnormally. |