Amazon FreeRTOS: POSIX
返回主页↑
pthread.h 文件引用

线程。 更多……

转到此文件的源代码。

pthread 分离状态。
#define PTHREAD_CREATE_DETACHED   0
 
#define PTHREAD_CREATE_JOINABLE   1
 
pthread_barrier_wait 成功后返回到单个线程。

POSIX 指定“常量 PTHREAD_BARRIER_SERIAL_THREAD 定义于 <pthread.h>,且其值应不同于 pthread_barrier_wait() 返回的任何其他值。" 因此,它被定义为负以与正值的 errno 区分。

#define PTHREAD_BARRIER_SERIAL_THREAD   ( -2 )
 
互斥锁类型。
#define PTHREAD_MUTEX_NORMAL   0
 
#define PTHREAD_MUTEX_ERRORCHECK   1
 
#define PTHREAD_MUTEX_RECURSIVE   2
 
#define PTHREAD_MUTEX_DEFAULT   PTHREAD_MUTEX_NORMAL
 

函数

int pthread_attr_destroy (pthread_attr_t *attr)
 销毁线程属性对象。 更多……
 
int pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)
 获取 detachstate 属性。 更多……
 
int pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *param)
 获取 scheduleparam 属性。 更多……
 
int pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)
 获取 stacksize 属性。 更多……
 
int pthread_attr_init (pthread_attr_t *attr)
 初始化线程属性对象。 更多……
 
int pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
 设置 detachstate 属性。 更多……
 
int pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *param)
 设置 scheduleparam 属性。 更多……
 
int pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)
 设置 schedpolicy 属性。 更多……
 
int pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize)
 设置 stacksize 属性。 更多……
 
int pthread_barrier_destroy (pthread_barrier_t *barrier)
 销毁障碍对象。 更多……
 
int pthread_barrier_init (pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count)
 初始化障碍对象。 更多……
 
int pthread_barrier_wait (pthread_barrier_t *barrier)
 在障碍处同步。 更多……
 
int pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*startroutine)(void *), void *arg)
 线程创建。 更多……
 
int pthread_cond_broadcast (pthread_cond_t *cond)
 广播条件。 更多……
 
int pthread_cond_destroy (pthread_cond_t *cond)
 销毁条件变量。 更多……
 
int pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr)
 初始化条件变量。 更多……
 
int pthread_cond_signal (pthread_cond_t *cond)
 发出条件信号。 更多……
 
int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
 等待超时条件。 更多……
 
int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
 等待条件发生。 更多……
 
int pthread_equal (pthread_t t1, pthread_t t2)
 比较线程 ID。 更多……
 
void pthread_exit (void *value_ptr)
 线程终止。 更多……
 
int pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param)
 动态线程调度参数访问。 更多……
 
int pthread_join (pthread_t thread, void **retval)
 等待线程终止。 更多……
 
int pthread_mutex_destroy (pthread_mutex_t *mutex)
 销毁互斥锁。 更多……
 
int pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
 初始化互斥锁。 更多……
 
int pthread_mutex_lock (pthread_mutex_t *mutex)
 锁定互斥锁。 更多……
 
int pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime)
 锁定带超时时间的互斥锁。 更多……
 
int pthread_mutex_trylock (pthread_mutex_t *mutex)
 尝试锁定互斥锁。如果互斥锁已锁定,操作将立即失败。 更多……
 
int pthread_mutex_unlock (pthread_mutex_t *mutex)
 解锁互斥锁。 更多……
 
int pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
 销毁互斥锁属性对象。 更多……
 
int pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type)
 获取互斥锁类型属性。 更多……
 
int pthread_mutexattr_init (pthread_mutexattr_t *attr)
 初始化互斥锁属性对象。 更多……
 
int pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type)
 设置互斥锁类型属性。 更多……
 
pthread_t pthread_self (void)
 获取调用线程 ID。 更多……
 
int pthread_setschedparam (pthread_t thread, int policy, const struct sched_param *param)
 动态线程调度参数访问。 更多……
 

详细描述

宏定义文档

◆ PTHREAD_CREATE_DETACHED

#define PTHREAD_CREATE_DETACHED   0

分离。

◆ PTHREAD_CREATE_JOINABLE

#define PTHREAD_CREATE_JOINABLE   1

可联接(默认)。

◆ PTHREAD_MUTEX_NORMAL

#define PTHREAD_MUTEX_NORMAL   0

不稳健,重新锁定时出现死锁,不记录所有者。

◆ PTHREAD_MUTEX_ERRORCHECK

#define PTHREAD_MUTEX_ERRORCHECK   1

不稳健,重新锁定时出错,记录所有者。

◆ PTHREAD_MUTEX_RECURSIVE

#define PTHREAD_MUTEX_RECURSIVE   2

不稳健,递归重新锁定,记录所有者。

◆ PTHREAD_MUTEX_DEFAULT

#define PTHREAD_MUTEX_DEFAULT   PTHREAD_MUTEX_NORMAL

PTHREAD_MUTEX_NORMAL(默认)。

函数文档

◆ pthread_attr_destroy()

int pthread_attr_destroy ( pthread_attr_t attr)

销毁线程属性对象。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_destroy.html
返回值
0——成功完成后。

◆ pthread_attr_getdetachstate()

int pthread_attr_getdetachstate ( const pthread_attr_t attr,
int *   detachstate 
)

获取分离状态属性。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getdetachstate.html
返回值
0——成功完成后。

◆ pthread_attr_getschedparam()

int pthread_attr_getschedparam ( const pthread_attr_t attr,
struct sched_param param 
)

获取 scheduleparam 属性。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getschedparam.html
返回值
0——成功完成后。

◆ pthread_attr_getstacksize()

int pthread_attr_getstacksize ( const pthread_attr_t attr,
size_t *  stacksize 
)

获取 stacksize 属性。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstacksize.html
返回值
0——成功完成后。

◆ pthread_attr_init()

int pthread_attr_init ( pthread_attr_t attr)

初始化线程属性对象。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_init.html
返回值
0——成功完成后。
注意事项
目前,仅支持 stack size、sched_param 和分离状态属性。另请参阅 pthread_attr_get*() 和 pthread_attr_set*()。

◆ pthread_attr_setdetachstate()

int pthread_attr_setdetachstate ( pthread_attr_t attr,
int  detachstate 
)

设置 detachstate 属性。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setdetachstate.html
返回值
0——成功完成后
参数无效- detachstate 的值无效。目前,支持的分离状态为 – PTHREAD_CREATE_DETACHED 及 PTHREAD_CREATE_JOINABLE。

◆ pthread_attr_setschedparam()

int pthread_attr_setschedparam ( pthread_attr_t attr,
const struct sched_param param 
)

设置 scheduleparam 属性。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedparam.html
返回值
0——成功完成后。
参数无效-param 的值无效。
不受支持- 试图将属性设置为不受支持的值。

◆ pthread_attr_setschedpolicy()

int pthread_attr_setschedpolicy ( pthread_attr_t attr,
int  policy 
)

设置 schedpolicy 属性。

http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedpolicy.html

返回值
0——成功完成后。
警告
此函数是一个桩代码,始终返回0。

◆ pthread_attr_setstacksize()

int pthread_attr_setstacksize ( pthread_attr_t attr,
size_t  stacksize 
)

设置 stacksize 属性。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setstacksize.html
返回值
0——成功完成后。
无效参数-stacksize 的值小于 {PTHREAD_STACK_MIN}。

◆ pthread_barrier_destroy()

int pthread_barrier_destroy ( pthread_barrier_t barrier)

销毁障碍对象。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_barrier_destroy.html
返回值
0——成功完成后。
注意事项
此函数在销毁之前未验证障碍上是否有任何线程阻塞。

◆ pthread_barrier_init()

int pthread_barrier_init ( pthread_barrier_t barrier,
const pthread_barrierattr_t attr,
unsigned  count 
)

初始化障碍对象。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_barrier_init.html
返回值
0——成功完成后。
EINVAL——由 count 指定的值等于 0。
ENOMEM—— count 不适合 FreeRTOS 事件组类型,或者内存不足导致无法初始化障碍。
注意事项
attr 被忽略。
pthread_barrier_init() 在 FreeRTOS 事件组中实现。为了确保 count 适合事件组,当 configUSE_16_BIT_TICKS 为 1 时,count 最多可为 8 ;否则最多可为 24。configUSE_16_BIT_TICKS 在应用程序 FreeRTOSConfig.h 文件中进行配置,该文件定义了 tick count 类型有多少位。在 FreeRTOS 网站中查看有关事件组和 configUSE_16_BIT_TICKS 的更多详细信息和限制。

◆ pthread_barrier_wait()

int pthread_barrier_wait ( pthread_barrier_t barrier)

在障碍上同步。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_barrier_wait.html
返回值
PTHREAD_BARRIER_SERIAL_THREAD———成功完成后,第一个线程。
0———成功完成后,其他线程。

◆ pthread_create()

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

线程创建。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html
返回值
0———成功完成后。
资源不足-内存不足,无法进行线程结构或任务创建。

◆ pthread_cond_broadcast()

int pthread_cond_broadcast ( pthread_cond_t cond)

广播条件。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_broadcast.html
返回值
0——成功完成后。

◆ pthread_cond_destroy()

int pthread_cond_destroy ( pthread_cond_t cond)

销毁条件变量。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_destroy.html
返回值
0——成功完成后。

◆ pthread_cond_init()

int pthread_cond_init ( pthread_cond_t cond,
const pthread_condattr_t attr 
)

初始化条件变量。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_init.html
返回值
0——成功完成后。
ENOMEM-内存不足,无法初始化条件变量。
注意事项
attr 被忽略并作为 NULL 处理。始终使用默认设置。

◆ pthread_cond_signal()

int pthread_cond_signal ( pthread_cond_t cond)

发出条件信号。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_signal.html
返回值
0——成功完成后。

◆ pthread_cond_timedwait()

int pthread_cond_timedwait ( pthread_cond_t cond,
pthread_mutex_t mutex,
const struct timespec abstime 
)

在超时状态下等待。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html
返回值
0——成功完成后。
EINVAL-传入的 Abstime 参数不引用初始化的结构或 Abstime 参数指定小于 0 或大于等于 10 亿的纳秒字段值。
ETIMEDOUT-Abstime指定给 pthread_cond_timedwait() 的时间已经过去。

◆ pthread_cond_wait()

int pthread_cond_wait ( pthread_cond_t cond,
pthread_mutex_t mutex 
)

等待条件。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_wait.html
返回值
0——成功完成后。

◆ pthread_equal()

int pthread_equal ( pthread_t  t1,
pthread_t  t2 
)

比较线程 ID。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_equal.html
返回值
0- t1 和 t2 均不等于 NULL && 和相等。
非零——其他情况。

◆ pthread_exit()

void pthread_exit ( void *  value_ptr)

线程终止。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_exit.html
返回值
无效- 此函数无法返回到其调用方。

◆ pthread_getschedparam()

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

动态线程调度参数访问。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getschedparam.html
返回值
0——成功完成后。
注意事项
始终由此函数将策略设置为 Sched_OTHER。

◆ pthread_join()

int pthread_join ( pthread_t  thread,
void **  retval 
)

等待线程终止。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html
返回值
0——成功完成后。
死锁错误- 由线程参数指定给 pthread_join()的值不是指一个可连接的线程,或者给指定同一目标线程的pthread_join()的多个同步调用 ,或者由线程参数指定给 pthread_join()的值指该调用线程。

◆ pthread_mutex_destroy()

int pthread_mutex_destroy ( pthread_mutex_t mutex)

销毁互斥锁。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_destroy.html
返回值
0——成功完成后。
注意事项
如果存在包含此互斥锁的线程,则此函数返回 0,但未销毁互斥锁。

◆ pthread_mutex_init()

int pthread_mutex_init ( pthread_mutex_t mutex,
const pthread_mutexattr_t attr 
)

初始化互斥锁。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html
返回值
0——成功完成后。
ENOMEM-内存不足,无法初始化互斥锁结构。
EAGAIN-无法初始化互斥锁结构成员。

◆ pthread_mutex_lock()

int pthread_mutex_lock ( pthread_mutex_t mutex)

锁定互斥锁。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html
返回值
0——成功完成后。
EINVAL-Abstime 参数指定小于 0 或大于等于 10 亿的纳秒字段值。
EDEADLK-互斥锁类型为 PTHREAD_MUTEX_ERRORCHECK ,当前线程已经拥有互斥锁。

◆ pthread_mutex_timedlock()

int pthread_mutex_timedlock ( pthread_mutex_t mutex,
const struct timespec abstime 
)

锁定超时互斥锁。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_timedlock.html
返回值
0——成功完成后。
EINVAL-传入的Abstime参数不引用初始化结构或Abstime参数指定小于0或大于等于10亿的纳秒字段值。
EDEADLK-互斥锁类型为 PTHREAD_MUTEX_ERRORCHECK,当前线程已经拥有互斥锁。
ETIMEDOUT-在指定的超时到期之前无法锁定互斥锁。

◆ pthread_mutex_trylock()

int pthread_mutex_trylock ( pthread_mutex_t mutex)

尝试锁定互斥锁。如果互斥锁已锁定,操作将立即失败。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_trylock.html
返回值
0——成功完成后。
EINVAL-Abstime 参数指定小于 0 或大于等于 10 亿的纳秒字段值。
EDEADLK-互斥锁类型为 PTHREAD_MUTEX_ERRORCHECK ,当前线程已经拥有互斥锁。
EBUSY-互斥锁已被锁定,无法获取。

◆ pthread_mutex_unlock()

int pthread_mutex_unlock ( pthread_mutex_t mutex)

解锁互斥锁。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_unlock.html
返回值
0——成功完成后。
EPERM-互斥锁类型为 PTHREAD_MUTEX_ERRORCHECK 或 PTHREAD_MUTEX_RECURSIVE,并且当前线程不拥有互斥锁。

◆ pthread_mutexattr_destroy()

int pthread_mutexattr_destroy ( pthread_mutexattr_t attr)

摧毁互斥锁属性对象。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_destroy.html
返回值
0——成功完成后。

◆ pthread_mutexattr_gettype()

int pthread_mutexattr_gettype ( const pthread_mutexattr_t attr,
int *  type 
)

获取互斥锁类型属性。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_gettype.html
返回值
0——成功完成后。

◆ pthread_mutexattr_init()

int pthread_mutexattr_init ( pthread_mutexattr_t attr)

初始化互斥锁属性对象。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_init.html
返回值
0——成功完成后。
注意事项
目前,仅支持类型属性。另请参阅 pthread_mutexattr_settype()pthread_mutexattr_gettype()

◆ pthread_mutexattr_settype()

int pthread_mutexattr_settype ( pthread_mutexattr_t attr,
int  type 
)

设置互斥锁类型属性。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_settype.html
返回值
0——成功完成后。
EINVAL-值类型无效。

◆ pthread_self()

pthread_t pthread_self ( void  )

获取调用线程 ID。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html
返回值
tHE调用线程的线程 ID。

◆ pthread_setschedparam()

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

动态线程调度参数访问。

另请参阅
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_setschedparam.html
注意事项
策略被忽略;可能更改优先级(param.sched_priority)。
返回值
0——成功完成后。