加入收藏
举报
02-14 20:02
#0
文件名称:
PROCESS.md
所在目录:
Openharmony v1.0 / docs / api / api-SmartVision-Devices
文件大小:
297.04 KB
下载地址:
fenwii/OpenHarmony
   
免责声明:本网站仅提供指向 GitHub 上的文件的链接,所有文件的版权归原作者所有,本网站不对文件内容的合法性、准确性或安全性承担任何责任。
文本预览:
# PROCESS
## **Overview**
Provides process- and thread-related structures and functions.
**Since:**
1.0
**Version:**
1.0
## **Summary**
## Files





















File Name


Description


pthread.h


Provides process- and thread-related structures (providing fields such as thread attributes) and functions (including the functions for creating and destroying threads, and setting the thread detach state and blocking conditions).


sched.h


Provides process- and thread-related structures and functions (for example, obtaining scheduling policies and parameters).


capability.h


Provides functions and related data structures for obtaining and setting process capabilities.


resource.h


Declares process-related structures and functions.


wait.h


Provides process- and thread-related structures and functions (for example, waiting for child processes to end and reclaiming resources).



## Data Structures









Data Structure Name


Description


sched_param


Defines process scheduling parameters.



## Functions















































































































































































































































































































Function Name


Description


pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)


int 


Creates a thread.


pthread_detach (pthread_t thread)


int 


Detaches a thread.


pthread_exit (void *retval)


_Noreturn void 


Terminates the calling thread.


pthread_join (pthread_t thread, void **retval)


int 


Waits for a thread to terminate.


pthread_self (void)


pthread_t 


Obtains the ID of the calling thread.


pthread_equal (pthread_t t1, pthread_t t2)


int 


Compares whether two thread IDs are equal.


pthread_setcancelstate (int state, int *oldstate)


int 


Sets the cancelability state for the calling thread.


pthread_setcanceltype (int type, int *oldtype)


int 


Sets the cancelability type for the calling thread.


pthread_testcancel (void)


void 


Requests delivery of any pending cancellation request.


pthread_cancel (pthread_t thread)


int 


Sends a cancellation request to a thread.


pthread_kill (pthread_t thread, int sig)


int 


Sends a signal to a thread.


pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param)


int 


Obtains the scheduling policy and parameters of a thread.


pthread_setschedparam (pthread_t thread, int policy, const struct sched_param *param)


int 


Sets a scheduling policy and parameters for a thread.


pthread_setschedprio (pthread_t thread, int prio)


int 


Sets a static scheduling priority for a thread.


pthread_once (pthread_once_t *once_control, void(*init_routine)(void))


int 


Enables the initialization function to be called only once.


pthread_mutex_init (pthread_mutex_t *__restrict m, const pthread_mutexattr_t *__restrict a)


int 


Initializes a mutex.


pthread_mutex_lock (pthread_mutex_t *m)


int 


Locks a mutex.


pthread_mutex_unlock (pthread_mutex_t *m)


int 


Unlocks a mutex.


pthread_mutex_trylock (pthread_mutex_t *m)


int 


Attempts to lock a mutex.


pthread_mutex_timedlock (pthread_mutex_t *__restrict m, const struct timespec *__restrict at)


int 


Blocks the calling thread to lock a mutex.


pthread_mutex_destroy (pthread_mutex_t *m)


int 


Destroys a mutex.


pthread_cond_init (pthread_cond_t *__restrict c, const pthread_condattr_t *__restrict a)


int 


Initializes a condition variable.


pthread_cond_destroy (pthread_cond_t *c)


int 


Destroys a condition variable.


pthread_cond_wait (pthread_cond_t *__restrict c, pthread_mutex_t *__restrict m)


int 


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)


int 


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)


int 


Unblocks all threads that are currently blocked on the condition variable cond.


pthread_cond_signal (pthread_cond_t *c)


int 


Unblocks a thread.


pthread_rwlock_init (pthread_rwlock_t *__restrict rw, const pthread_rwlockattr_t *__restrict a)


int 


Initializes a read-write lock.


pthread_rwlock_destroy (pthread_rwlock_t *rw)


int 


Destroys a read-write lock.


pthread_rwlock_rdlock (pthread_rwlock_t *rw)


int 


Applies a read lock to a read-write lock.


pthread_rwlock_tryrdlock (pthread_rwlock_t *rw)


int 


Attempts to apply a read lock to a read-write lock.


pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict rw, const struct timespec *__restrict at)


int 


Blocks the calling thread to lock a read-write lock for reading.


pthread_rwlock_wrlock (pthread_rwlock_t *rw)


int 


Applies a write lock to a read-write lock.


pthread_rwlock_trywrlock (pthread_rwlock_t *rw)


int 


Attempts to apply a write lock to a read-write lock.


pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict rw, const struct timespec *__restrict at)


int 


Blocks the calling thread to lock a read-write lock for writing.


pthread_rwlock_unlock (pthread_rwlock_t *rw)


int 


Unlocks a read-write lock.


pthread_spin_init (pthread_spinlock_t *s, int shared)


int 


Initializes a spin lock.


pthread_spin_destroy (pthread_spinlock_t *s)


int 


Destroys a spin lock.


pthread_spin_lock (pthread_spinlock_t *s)


int 


Locks a spin lock.


pthread_spin_trylock (pthread_spinlock_t *s)


int 


Attempts to lock a spin lock.


pthread_spin_unlock (pthread_spinlock_t *s)


int 


Unlocks a spin lock.


pthread_barrier_init (pthread_barrier_t *__restrict b, const pthread_barrierattr_t *__restrict a, unsigned count)


int 


Initializes a barrier.


pthread_barrier_destroy (pthread_barrier_t *b)


int 


Destroys a barrier.


pthread_barrier_wait (pthread_barrier_t *b)


int 


Synchronizes participating threads at a barrier.


pthread_key_create (pthread_key_t *key, void(*destructor)(void *))


int 


Creates a key for thread data.


pthread_key_delete (pthread_key_t key)


int 


Deletes a key for thread data.


pthread_getspecific (pthread_key_t key)


void * 


Obtains specific thread data.


pthread_setspecific (pthread_key_t key, const void *value)


int 


Sets specific thread data.


pthread_attr_init (pthread_attr_t *attr)


int 


Initializes a thread attribute object.


pthread_attr_destroy (pthread_attr_t *attr)


int 


Destroys a thread attribute object.


pthread_attr_getguardsize (const pthread_attr_t *attr, size_t *guardsize)


int 


Obtains the guard size of a thread attribute object.


pthread_attr_setguardsize (pthread_attr_t *attr, size_t guardsize)


int 


Sets the guard size for a thread attribute object.


pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)


int 


Obtains the stack size of a thread attribute object.


pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize)


int 


Sets the stack size for a thread attribute object.


pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)


int 


Obtains the detach state of a thread attribute object.


pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)


int 


Sets the detach state for a thread attribute object.


pthread_attr_getstack (const pthread_attr_t *attr, void **stackaddr, size_t *stacksize)


int 


Obtains stack attributes of a thread attribute object.


pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, size_t stacksize)


int 


Sets stack attributes for a thread attribute object.


pthread_attr_getscope (const pthread_attr_t *arrt, int *scope)


int 


Obtains contention scope attributes of a thread attribute object.


pthread_attr_setscope (pthread_attr_t *arrt, int scope)


int 


Sets contention scope attributes for a thread attribute object.


pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *schedpolicy)


int 


Obtains scheduling policy attributes of a thread attribute object.


pthread_attr_setschedpolicy (pthread_attr_t *attr, int schedpolicy)


int 


Sets scheduling policy attributes for a thread attribute object.


pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *param)


int 


Obtains scheduling parameter attributes of a thread attribute object.


pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *param)


int 


Sets scheduling parameter attributes for a thread attribute object.


pthread_attr_getinheritsched (const pthread_attr_t *attr, int *inheritsched)


int 


Obtains inherit scheduler attributes of a thread attribute object.


pthread_attr_setinheritsched (pthread_attr_t *attr, int inheritsched)


int 


Sets inherit scheduler attributes for a thread attribute object.


pthread_mutexattr_destroy (pthread_mutexattr_t *attr)


int 


Destroys a mutex attribute object.


pthread_mutexattr_gettype (const pthread_mutexattr_t *__restrict attr, int *__restrict type)


int 


Obtains the mutex type attribute.


pthread_mutexattr_init (pthread_mutexattr_t *attr)


int 


Initializes a mutex attribute object.


pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type)


int 


Sets the mutex type attribute.


pthread_condattr_init (pthread_condattr_t *a)


int 


Initializes a condition variable attribute object.


pthread_condattr_destroy (pthread_condattr_t *a)


int 


Destroys a condition variable attribute object.


pthread_condattr_setclock (pthread_condattr_t *a, clockid_t clk)


int 


Sets a clock for a condition variable attribute object.


pthread_condattr_getclock (const pthread_condattr_t *__restrict a, clockid_t *__restrict clk)


int 


Obtains the clock of a condition variable attribute object.


pthread_rwlockattr_init (pthread_rwlockattr_t *attr)


int 


Initializes a read-write lock attribute object.


pthread_rwlockattr_destroy (pthread_rwlockattr_t *attr)


int 


Destroys a read-write lock attribute object.


pthread_barrierattr_destroy (pthread_barrierattr_t *a)


int 


Destroys a barrier attribute object.


pthread_barrierattr_init (pthread_barrierattr_t *a)


int 


Initializes a barrier attribute object.


pthread_atfork (void(*prepare)(void), void(*parent)(void), void(*child)(void))


int 


Registers a fork handler to be called before and after fork().


pthread_cleanup_push (void(*routine)(void *), void *arg)


void 


Pushes the routine to the top of the clean-up handler stack.


pthread_cleanup_pop (int execute)


void 


Removes the routine at the top of the clean-up handler stack.


pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)


int 


Obtains the attributes of a created thread.


pthread_setname_np (pthread_t pthread, const char *name)


int 


Sets the thread name.


sched_get_priority_max (int policy)


int 


Obtains the maximum static priority that can be used for a process.


sched_get_priority_min (int policy)


int 


Obtains the minimum static priority that can be used for a process.


sched_getparam (pid_t pid, struct sched_param *param)


int 


Obtains scheduling parameters of a process.


sched_getscheduler (pid_t pid)


int 


Obtains the scheduling policy of a process.


sched_rr_get_interval (pid_t pid, struct timespec *interval)


int 


Obtains the execution time limit of a process.


sched_setparam (pid_t pid, const struct sched_param *param)


int 


Sets scheduling parameters related to a scheduling policy for a process.


sched_setscheduler (pid_t pid, int policy, const struct sched_param *param)


int 


Sets a scheduling policy for a process.


sched_yield (void)


int 


Yields the running process.


capget (cap_user_header_t hdr_ptr, cap_user_data_t data_ptr)


int 


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)


int 


Sets the capability information for a specified process based on the input parameters (compatible with the Linux API format).


ohos_capget (unsigned int *caps)


int 


Obtains the capability information of a specified process based on the input parameters.


ohos_capset (unsigned int caps)


int 


Sets the capability information of a specified process based on the input parameters.


getpriority (int which, id_t who)


int 


Obtains the static priority of a specified ID.


setpriority (int which, id_t who, int value)


int 


Sets the static priority of a specified ID.


wait (int *status)


pid_t 


Waits for any child process to end and reclaims its resources.


waitpid (pid_t pid, int *status, int options)


pid_t 


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:**












Name


Description


hdr_ptr Indicates the data structure required for this function call, including the API version and the target process identifier (PID). The PID can only be set to 0.
data_ptr Indicates the buffer space for storing the process capabilities.

**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.















errno


Description


EINVAL


Incorrect parameter.


EPERM


No permission.


EFAULT


Invalid memory address.



## 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:**












Name


Description


hdr_ptr Indicates the data structure required for this function call, including the API version and the target PID. The PID can only be set to 0, representing the current process.
data_ptr Indicates the buffer space for storing the customized process capabilities. Currently, the following capabilities are supported (other values do not take effect): CAP_CHOWN: changes the permissions of file ownership. CAP_DAC_OVERRIDE: ignores discretionary access control (DAC) restrictions. CAP_DAC_READ_SEARCH: ignores DAC restrictions on file read and search. CAP_FOWNER: allows other users (not the file owner) to modify file permission configurations. CAP_KILL: allows the current process to send signals to other processes with different UIDs. CAP_SETGID: allows changing the group ID of the process. CAP_SETUID: allows changing the user ID of the process. CAP_SETPCAP: allows changing the capabilities. CAP_NET_BIND_SERVICE: allows the process to be bound to a port whose number is smaller than 1024. CAP_NET_BROADCAST: allows network broadcast or multicast. CAP_NET_ADMIN: allows network-related management functions. CAP_NET_RAW: allows raw sockets to be used. CAP_SYS_PTRACE: allows system commissioning. CAP_SYS_ADMIN: allows system management operations. CAP_SYS_NICE: allows priority increase and priority setting for other processes. CAP_SYS_TIME: allows changing the system clock. The cap_user_data_t structure contains three members: effective, permitted, and inheritable. inheritable is not implemented. effective is included in permitted. permitted and inheritable can only be decreased.

**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the creation fails.












errno


Description


EINVAL


Incorrect parameter.


EPERM


No permission.



## getpriority\(\)
```
int getpriority (int which, id_t who )
```
**Description:**
Obtains the static priority of a specified ID.
**Parameters:**












Name


Description


which Indicates a specified value. The values are as follows:
who Indicates the specified ID.
















value


Description


RIO_PROCESS


who indicates the ID of a specified process.


PRIO_PGRP


who indicates the ID of a specified process group. This value is not supported yet.


PRIO_USER


who indicates the ID of a specified valid user. This value is not supported yet.



**Returns:**
Returns the scheduling priority if the operation is successful; returns **-1** and sets **errno** to a value in the following table otherwise.












errno


Description


EINVAL


Invalid parameter.


EOPNOTSUPP


Unsupported value.



## ohos\_capget\(\)
```
int ohos_capget (unsigned int * caps)
```
**Description:**
Obtains the capability information of a specified process based on the input parameters.
**Parameters:**









Name


Description


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.









errno


Description


EFAULT


Invalid memory address.



## ohos\_capset\(\)
```
int ohos_capset (unsigned int caps)
```
**Description:**
Sets the capability information of a specified process based on the input parameters.
**Parameters:**









Name


Description


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.









errno


Description


EPERM


No permission.



## 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:**















Name


Description


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:**









Name


Description


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:**












Name


Description


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:**












Name


Description


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:**












Name


Description


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:**












Name


Description


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:**












Name


Description


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:**












Name


Description


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.









errno


Description


EINVAL


Invalid scope value.



## 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:**















Name


Description


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.









errno


Description


EINVAL


Invalid start address.



## 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:**












Name


Description


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:**









Name


Description


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:**












Name


Description


attr Indicates the pointer to the target thread attribute object.
detachstate Indicates the detach state to set. Available values are as follows:













detachstate


Description


PTHREAD_CREATE_DETACHED


Threads using attr are created in the detached state.


PTHREAD_CREATE_JOINABLE


Threads using attr are created in the joinable state.



**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.









errno


Description


EINVAL


Invalid detach state.



## 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:**












Name


Description


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.









errno


Description


EINVAL


Invalid guard size.



## pthread\_attr\_setinheritsched\(\)
```
int pthread_attr_setinheritsched (pthread_attr_t * attr, int inheritsched )
```
**Description:**
Sets inherit scheduler attributes for a thread attribute object.
**Parameters:**












Name


Description


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.









errno


Description


EINVAL


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:**












Name


Description


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.









errno


Description


EINVAL


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:**












Name


Description


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.









errno


Description


EINVAL


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:**












Name


Description


attr Indicates the pointer to the target thread attribute object.
scope Indicates the start address of the buffer that stores the target thread attribute object. By default, only PTHREAD_SCOPE_PROCESS is supported.

**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.









errno


Description


EINVAL


Invalid scope value.



## 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:**















Name


Description


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.









errno


Description


EINVAL


Invalid start address.



## 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:**












Name


Description


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.









errno


Description


EINVAL


Invalid stack size.



## pthread\_barrier\_destroy\(\)
```
int pthread_barrier_destroy (pthread_barrier_t * b)
```
**Description:**
Destroys a barrier.
This function always succeeds.
**Parameters:**









Name


Description


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:**















Name


Description


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.









errno


Description


EINVAL


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:**









Name


Description


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:**









Name


Description


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:**









Name


Description


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:**









Name


Description


thread Indicates the thread to receive the cancellation request.

**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.









errno


Description


EINVAL


Invalid parameter.



## pthread\_cleanup\_pop\(\)
```
void pthread_cleanup_pop (int execute)
```
**Description:**
Removes the routine at the top of the clean-up handler stack.
**Parameters:**









Name


Description


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:**












Name


Description


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:**









Name


Description


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:**









Name


Description


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:**












Name


Description


c Indicates the pointer to the condition variable to initialize.
a Indicates the pointer to the condition variable attribute object. If this parameter is set to NULL, the default condition variable attributes are used.

**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:**









Name


Description


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:**















Name


Description


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.












errno


Description


EINVAL


Invalid ts value.


EPERM


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:**












Name


Description


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.









errno


Description


EPERM


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:**









Name


Description


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:**












Name


Description


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:**









Name


Description


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:**












Name


Description


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.









errno


Description


EINVAL


Invalid clk> value.



## 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:**


















Name


Description


thread Indicates the pointer to the buffer for storing the thread ID.
attr Indicates the pointer to the thread attribute object. If this parameter is set to NULL, the default thread attributes are used.
start_routine Indicates the pointer to the entry point of the thread.
arg Functions as the unique argument of start_routine.

**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.















errno


Description


EINVAL


Invalid parameter.


EAGAIN


Insufficient resource, or the maximum number of threads allowed by the system reached.


ENOSYS


Unsupported system call.



## pthread\_detach\(\)
```
int pthread_detach (pthread_t thread)
```
**Description:**
Detaches a thread.

**Parameters:**









Name


Description


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.












errno


Description


EINVAL


The thread is not joinable.


ESRCH


Invalid thread ID.



## pthread\_equal\(\)
```
int pthread_equal (pthread_t t1, pthread_t t2 )
```
**Description:**
Compares whether two thread IDs are equal.
**Parameters:**












Name


Description


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:**









Name


Description


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:**












Name


Description


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:**















Name


Description


thread Indicates the target thread.
policy Indicates the pointer to the scheduling policy. The value can only be SCHED_FIFO or SCHED_RR.
param Indicates the pointer to the scheduling parameters. 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.















errno


Description


ESRCH


Invalid thread ID.


EINVAL


Invalid parameter.


EPERM


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:**









Name


Description


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:**












Name


Description


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.









errno


Description


EINVAL


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:**












Name


Description


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.









errno


Description


EAGAIN


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:**









Name


Description


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.









errno


Description


EINVAL


Invalid key.



## 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:**












Name


Description


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.












errno


Description


EINVAL


Invalid signal.


ESRCH


Invalid thread ID.



## pthread\_mutex\_destroy\(\)
```
int pthread_mutex_destroy (pthread_mutex_t * m)
```
**Description:**
Destroys a mutex.
This function always succeeds.
**Parameters:**









Name


Description


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:**












Name


Description


m Indicates the pointer to the mutex to initialize.
a Indicates the pointer to the mutex attribute object. If this parameter is set to NULL, the default mutex attributes are used. The default attributes indicate a fast mutex.

**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:**









Name


Description


m Indicates the pointer to the mutex to lock.

**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.


















errno


Description


EINVAL


Incorrect parameter value.


EBADF


The mutex has been damaged during the waiting.


EDEADLK


The thread attempts to relock the mutex that it has already locked, and the mutex is of the error check mutex type.


EAGAIN


The maximum number of recursive locks for the mutex has been exceeded.



## 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:**












Name


Description


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.





















errno


Description


EINVAL


Incorrect parameter value.


EBADF


The mutex has been damaged during the waiting.


EBUSY


The mutex is already locked.


EAGAIN


The maximum number of recursive locks for the mutex has been exceeded.


ETIMEDOUT


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:**









Name


Description


m Indicates the pointer to the mutex to lock.

**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.


















errno


Description


EINVAL


Incorrect parameter value.


EBADF


The mutex has been damaged during the waiting.


EBUSY


The mutex is already locked.


EAGAIN


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:**









Name


Description


m Indicates the pointer to the mutex to unlock.

**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.












errno


Description


EINVAL


Incorrect parameter value.


EPERM


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:**









Name


Description


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:**












Name


Description


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:**









Name


Description


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:**












Name


Description


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.









errno


Description


EINVAL


Invalid mutex type attribute.



## 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:**












Name


Description


once_control Indicates the pointer to a variable specifying the execution status. The value 0 means NEVER, 1 means IN PROGRESS, and 2 means DONE.
init_routine Indicates the pointer to the function that you want to call for any required initialization.

**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:**









Name


Description


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:**












Name


Description


rw Indicates the pointer to the read-write lock to initialize.
a Indicates the pointer to the read-write lock attribute object. If this parameter is set to NULL, the default read-write lock attributes are used.

**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:**









Name


Description


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.












errno


Description


EINVAL


Incorrect parameter value.


EBADF


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:**












Name


Description


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.


















errno


Description


EINVAL


Incorrect parameter value.


EBADF


The read-write lock has been damaged during the waiting.


EBUSY


The read-write lock is already locked.


ETIMEDOUT


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:**












Name


Description


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.


















errno


Description


EINVAL


Incorrect parameter value.


EBADF


The read-write lock has been damaged during the waiting.


EBUSY


The read-write lock is already locked.


ETIMEDOUT


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:**









Name


Description


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.















errno


Description


EINVAL


Incorrect parameter value.


EBADF


The read-write lock has been damaged during the waiting.


EBUSY


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:**









Name


Description


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.















errno


Description


EINVAL


Incorrect parameter value.


EBADF


The read-write lock has been damaged during the waiting.


EBUSY


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:**









Name


Description


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.












errno


Description


EINVAL


Incorrect parameter value.


EPERM


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:**









Name


Description


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.















errno


Description


EINVAL


Incorrect parameter value.


EBADF


The read-write lock has been damaged during the waiting.


EBUSY


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:**









Name


Description


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:**









Name


Description


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:**












Name


Description


state Indicates the cancelability state to set. Available values are as follows:
oldstate Indicates the pointer to the previous cancelability state before the setting.













state


Description


PTHREAD_CANCEL_ENABLE


The thread is cancelable.


PTHREAD_CANCEL_DISABLE


The thread is not cancelable.



**Returns:**
Returns **0** if the operation is successful; returns a value listed in **errno** otherwise.









errno


Description


EINVAL


Invalid parameter.



## 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:**












Name


Description


type Indicates the cancelability type to set. Available values are as follows:
oldtype Indicates the pointer to the previous cancelability type before the setting.













type


Description


PTHREAD_CANCEL_DEFERRED


The thread is canceled until the next cancellation point.


PTHREAD_CANCEL_ASYNCHRONOUS


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.









errno


Description


EINVAL


Invalid parameter.



## pthread\_setname\_np\(\)
```
int pthread_setname_np (pthread_t pthread, const char * name )
```
**Description:**
Sets the thread name.
**Parameters:**












Name


Description


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.












errno


Description


ERANGE


The name is too long.


EPERM


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:**















Name


Description


thread Indicates the target thread.
policy Indicates the scheduling policy to set. The value can only be SCHED_FIFO or SCHED_RR.
param Indicates the pointer to the scheduling parameters 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. If the operation fails, the scheduling policy and parameters of the target thread remain unchanged.















errno


Description


ESRCH


Invalid thread ID.


EINVAL


Invalid parameter.


EPERM


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:**












Name


Description


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.















errno


Description


ESRCH


Invalid thread ID.


EINVAL


Invalid parameter.


EPERM


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:**












Name


Description


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:**









Name


Description


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:**












Name


Description


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:**









Name


Description


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:**









Name


Description


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.









errno


Description


EBUSY


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:**









Name


Description


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:**









Name


Description


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.












errno


Description


EINVAL


Invalid parameter. The value of policy is not a defined scheduling policy.


ENOSYS


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:**









Name


Description


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.












errno


Description


EINVAL


Invalid parameter. The value of policy is not a defined scheduling policy.


ENOSYS


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:**












Name


Description


pid Indicates the ID of the process for which the scheduling parameters are to be obtained. If this parameter is set to 0, the scheduling parameters of the calling process are to be obtained.
param Indicates the pointer to the scheduling parameters. Only the static priority is supported. The priority ranges from 10 (highest priority) to 31 (lowest priority).

**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.












errno


Description


EINVAL


Invalid parameter.


ESRCH


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:**









Name


Description


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.















errno


Description


EINVAL


Invalid parameter.


EPERM


No permission.


ESRCH


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:**












Name


Description


pid Indicates the ID of the process for which the execution time limit is to be obtained. If this parameter is <0>0, the time quantum of the calling process is obtained and written into the parameter interval.
interval Indicates the pointer to the time structure that records the time limit. The time structure supports only seconds and nanoseconds.

**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.















errno


Description


EFAULT


An error occurred when copying information to the user space.


EINVAL


Invalid parameter.


ESRCH


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:**












Name


Description


pid Indicates the ID of the process for which the scheduling parameters are to be set. If this parameter is set to 0, the scheduling parameters of the calling process are to be set.
param Indicates the pointer to the scheduling parameters to set. Only the static priority can be set. The priority ranges from 10 (highest priority) to 31 (lowest priority).

**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.















errno


Description


EINVAL


Invalid parameter.


EPERM


No permission.


ESRCH


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:**















Name


Description


pid Indicates the ID of the process for which the scheduling policy and parameters are to be set. If this parameter is set to 0, the scheduling policy and parameters of the calling process are to be set.
policy Indicates the scheduling policy to set. The value can be SCHED_FIFO or SCHED_RR, but not SCHED_OTHER, SCHED_BATCH, SCHED_IDLE, or SCHED_DEADLINE.
param Indicates the pointer to the scheduling parameters to set. Only the static priority can be set. The priority ranges from 10 (highest priority) to 31 (lowest priority).

**Returns:**
Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.















errno


Description


EINVAL


Invalid parameter.


EPERM


No permission.


ESRCH


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:**















Name


Description


which Indicates a specified value. The values are as follows:
who Indicates the specified ID.
value Indicates the target priority to set.
















value


Description


RIO_PROCESS


who indicates the ID of a specified process.


PRIO_PGRP


who indicates the ID of a specified process group. This value is not supported yet.


PRIO_USER


who indicates the ID of a specified valid user. This value is not supported yet.



**Returns:**
Returns the scheduling priority if the operation is successful; returns **-1** and sets **errno** to a value in the following table otherwise.















errno


Description


EINVAL


Invalid parameter.


EPERM


The operation is not allowed.


EOPNOTSUPP


Unsupported value.



## wait\(\)
```
pid_t wait (int * status)
```
**Description:**
Waits for any child process to end and reclaims its resources.
**Parameters:**









Name


Description


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):
  • WIFEXITED(status): If the child process ends normally, true is returned. Otherwise, false is returned.
  • WEXITSTATUS(status): If WIFEXITED(status) is true, this macro can be used to obtain the exit code that the child process passed to exit().
  • WTERMSIG(status): After a child process ends abnormally, the parent process can obtain the child process exit code SIGUSR2 through WTERMSIG, indicating that the child process ends abnormally. This is the only case 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.












errno


Description


ECHILD


The child process does not exist, or the specified process group does not exist.


ESRCH


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:**















Name


Description


pid Indicates the ID of the child process to wait for.
  • If this parameter is less than -1, the system waits for any child process whose process group ID is the absolute value of pid.
  • If this parameter is -1, the system waits for any child process. In this case, this function is equivalent to wait().
  • If this parameter is 0, the system waits for a child process whose process group ID is the same as the calling process (any process that is in the same process group as the calling process).
  • If this parameter is greater than 0, the system waits for the child process whose process ID is the value of pid.

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):
  • WIFEXITED(status): If the child process ends normally, true is returned. Otherwise, false is returned.
  • WEXITSTATUS(status): If WIFEXITED(status) is true, this macro can be used to obtain the exit code that the child process passed to exit().
  • WTERMSIG(status): After a child process ends abnormally, the parent process can obtain the child process exit code SIGUSR2 through WTERMSIG, indicating that the child process ends abnormally. This is the only case supported.

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.


















errno


Description


EINVAL


Invalid options.


EOPNOTSUPP


Unsupported options.


ECHILD


The child process does not exist, or the specified process group does not exist.


ESRCH


The child process ends abnormally.


点赞 回复
回帖
支持markdown部分语法 ?