| 1 |
'\" t |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH pthread_attr_setscope 3 2025-05-17 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
pthread_attr_setscope, pthread_attr_getscope \- set/get contention scope |
| 9 |
attribute in thread attributes object |
| 10 |
.SH LIBRARY |
| 11 |
POSIX threads library |
| 12 |
.RI ( libpthread ,\~ \-lpthread ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <pthread.h> |
| 16 |
.P |
| 17 |
.BI "int pthread_attr_setscope(pthread_attr_t *" attr ", int " scope ); |
| 18 |
.BI "int pthread_attr_getscope(const pthread_attr_t *restrict " attr , |
| 19 |
.BI " int *restrict " scope ); |
| 20 |
.fi |
| 21 |
.SH DESCRIPTION |
| 22 |
The |
| 23 |
.BR pthread_attr_setscope () |
| 24 |
function sets the contention scope attribute of the |
| 25 |
thread attributes object referred to by |
| 26 |
.I attr |
| 27 |
to the value specified in |
| 28 |
.IR scope . |
| 29 |
The contention scope attribute defines the set of threads |
| 30 |
against which a thread competes for resources such as the CPU. |
| 31 |
POSIX.1 specifies two possible values for |
| 32 |
.IR scope : |
| 33 |
.TP |
| 34 |
.B PTHREAD_SCOPE_SYSTEM |
| 35 |
The thread competes for resources with all other threads |
| 36 |
in all processes on the system that are in the same scheduling |
| 37 |
allocation domain (a group of one or more processors). |
| 38 |
.B PTHREAD_SCOPE_SYSTEM |
| 39 |
threads are scheduled relative to one another |
| 40 |
according to their scheduling policy and priority. |
| 41 |
.TP |
| 42 |
.B PTHREAD_SCOPE_PROCESS |
| 43 |
The thread competes for resources with all other threads |
| 44 |
in the same process that were also created with the |
| 45 |
.B PTHREAD_SCOPE_PROCESS |
| 46 |
contention scope. |
| 47 |
.B PTHREAD_SCOPE_PROCESS |
| 48 |
threads are scheduled relative to other threads in the process |
| 49 |
according to their scheduling policy and priority. |
| 50 |
POSIX.1 leaves it unspecified how these threads contend |
| 51 |
with other threads in other process on the system or |
| 52 |
with other threads in the same process that |
| 53 |
were created with the |
| 54 |
.B PTHREAD_SCOPE_SYSTEM |
| 55 |
contention scope. |
| 56 |
.P |
| 57 |
POSIX.1 requires that an implementation support at least one of these |
| 58 |
contention scopes. |
| 59 |
Linux supports |
| 60 |
.BR PTHREAD_SCOPE_SYSTEM , |
| 61 |
but not |
| 62 |
.BR PTHREAD_SCOPE_PROCESS . |
| 63 |
.P |
| 64 |
On systems that support multiple contention scopes, then, |
| 65 |
in order for the parameter setting made by |
| 66 |
.BR pthread_attr_setscope () |
| 67 |
to have effect when calling |
| 68 |
.BR pthread_create (3), |
| 69 |
the caller must use |
| 70 |
.BR pthread_attr_setinheritsched (3) |
| 71 |
to set the inherit-scheduler attribute of the attributes object |
| 72 |
.I attr |
| 73 |
to |
| 74 |
.BR PTHREAD_EXPLICIT_SCHED . |
| 75 |
.P |
| 76 |
The |
| 77 |
.BR pthread_attr_getscope () |
| 78 |
function returns the contention scope attribute of the |
| 79 |
thread attributes object referred to by |
| 80 |
.I attr |
| 81 |
in the buffer pointed to by |
| 82 |
.IR scope . |
| 83 |
.SH RETURN VALUE |
| 84 |
On success, these functions return 0; |
| 85 |
on error, they return a nonzero error number. |
| 86 |
.SH ERRORS |
| 87 |
.BR pthread_attr_setscope () |
| 88 |
can fail with the following errors: |
| 89 |
.TP |
| 90 |
.B EINVAL |
| 91 |
An invalid value was specified in |
| 92 |
.IR scope . |
| 93 |
.TP |
| 94 |
.B ENOTSUP |
| 95 |
.I scope |
| 96 |
specified the value |
| 97 |
.BR PTHREAD_SCOPE_PROCESS , |
| 98 |
which is not supported on Linux. |
| 99 |
.SH ATTRIBUTES |
| 100 |
For an explanation of the terms used in this section, see |
| 101 |
.BR attributes (7). |
| 102 |
.TS |
| 103 |
allbox; |
| 104 |
lbx lb lb |
| 105 |
l l l. |
| 106 |
Interface Attribute Value |
| 107 |
T{ |
| 108 |
.na |
| 109 |
.nh |
| 110 |
.BR pthread_attr_setscope (), |
| 111 |
.BR pthread_attr_getscope () |
| 112 |
T} Thread safety MT-Safe |
| 113 |
.TE |
| 114 |
.SH STANDARDS |
| 115 |
POSIX.1-2008. |
| 116 |
.SH HISTORY |
| 117 |
POSIX.1-2001. |
| 118 |
.SH NOTES |
| 119 |
The |
| 120 |
.B PTHREAD_SCOPE_SYSTEM |
| 121 |
contention scope typically indicates that a user-space thread is |
| 122 |
bound directly to a single kernel-scheduling entity. |
| 123 |
This is the case on Linux for the obsolete LinuxThreads implementation |
| 124 |
and the modern NPTL implementation, |
| 125 |
which are both 1:1 threading implementations. |
| 126 |
.P |
| 127 |
POSIX.1 specifies that the default contention scope is |
| 128 |
implementation-defined. |
| 129 |
.SH SEE ALSO |
| 130 |
.ad l |
| 131 |
.nh |
| 132 |
.BR pthread_attr_init (3), |
| 133 |
.BR pthread_attr_setaffinity_np (3), |
| 134 |
.BR pthread_attr_setinheritsched (3), |
| 135 |
.BR pthread_attr_setschedparam (3), |
| 136 |
.BR pthread_attr_setschedpolicy (3), |
| 137 |
.BR pthread_create (3), |
| 138 |
.BR pthreads (7) |