返回值

成功时,pthread_setconcurrency()返回0;否则,返回0。如果出错,则返回非零错误号。

pthread_getconcurrency()总是成功,返回先前调用pthread_setconcurrency()设置的并发级别,如果先前未调用pthread_setconcurrency(),则返回0。

PTHREAD_SETCONCURRENCY - Linux手册页

Linux程序员手册 第3部分
更新日期: 2017-09-15

出版信息

这个页面是Linux手册页项目5.08版的一部分。有关项目的说明、有关报告错误的信息以及此页面的最新版本,请访问https://www.kernel.org/doc/man-pages/

另外参见

pthread_attr_setscope(3),pthreads(7)

说明

pthread_setconcurrency()函数通知应用程序所需的并发级别的实现,该级别在new_level中指定。该实现仅将其用作提示:POSIX.1没有指定由于调用pthread_setconcurrency()而应提供的并发级别。

将new_level指定为0会指示实现在认为适当的情况下管理并发级别。

pthread_getconcurrency()返回此进程的并发级别的当前值。

名称

pthread_setconcurrency,pthread_getconcurrency-设置/获取并发级别

错误说明

pthread_setconcurrency()可能因以下错误而失败:

EINVAL
new_level为负。

POSIX.1还记录了EAGAIN错误(" new_level指定的值将导致超出系统资源")。

版本

从2.1版开始,这些功能在glibc中可用。

语法

#include <pthread.h>

int pthread_setconcurrency(int new_level);
int pthread_getconcurrency(void);

Compile and link with -pthread.

备注

默认并发级别为0。

并发级别仅对M:N线程实现有意义,在该实现中,进程的用户级别线程集的子集随时可能绑定到较少数量的内核调度实体。设置并发级别允许应用程序向系统提示应该为有效执行应用程序而提供的内核调度实体的数量。

LinuxThreads和NPTL都是1:1线程实现,因此设置并发级别没有任何意义。换句话说,在Linux上存在这些功能仅仅是为了与其他系统兼容,而对程序的执行没有影响。

属性

有关本节中使用的术语的说明,请参见attribute(7)。

InterfaceAttributeValue
pthread_setconcurrency(),pthread_getconcurrency()Thread safetyMT-Safe

遵循规范

POSIX.1-2001,POSIX.1-2008。

日期:2019-08-20 18:01:05 来源:oir作者:oir