]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/pthread_attr_setscope.3
Various pages: [Linux-man-pages-copyleft] Use SPDX-License-Identifier
[thirdparty/man-pages.git] / man3 / pthread_attr_setscope.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH PTHREAD_ATTR_SETSCOPE 3 2021-03-22 "Linux" "Linux Programmer's Manual"
7 .SH NAME
8 pthread_attr_setscope, pthread_attr_getscope \- set/get contention scope
9 attribute in thread attributes object
10 .SH SYNOPSIS
11 .nf
12 .B #include <pthread.h>
13 .PP
14 .BI "int pthread_attr_setscope(pthread_attr_t *" attr ", int " scope );
15 .BI "int pthread_attr_getscope(const pthread_attr_t *restrict " attr ,
16 .BI " int *restrict " scope );
17 .PP
18 Compile and link with \fI\-pthread\fP.
19 .fi
20 .SH DESCRIPTION
21 The
22 .BR pthread_attr_setscope ()
23 function sets the contention scope attribute of the
24 thread attributes object referred to by
25 .I attr
26 to the value specified in
27 .IR scope .
28 The contention scope attribute defines the set of threads
29 against which a thread competes for resources such as the CPU.
30 POSIX.1 specifies two possible values for
31 .IR scope :
32 .TP
33 .B PTHREAD_SCOPE_SYSTEM
34 The thread competes for resources with all other threads
35 in all processes on the system that are in the same scheduling
36 allocation domain (a group of one or more processors).
37 .B PTHREAD_SCOPE_SYSTEM
38 threads are scheduled relative to one another
39 according to their scheduling policy and priority.
40 .TP
41 .B PTHREAD_SCOPE_PROCESS
42 The thread competes for resources with all other threads
43 in the same process that were also created with the
44 .BR PTHREAD_SCOPE_PROCESS
45 contention scope.
46 .BR PTHREAD_SCOPE_PROCESS
47 threads are scheduled relative to other threads in the process
48 according to their scheduling policy and priority.
49 POSIX.1 leaves it unspecified how these threads contend
50 with other threads in other process on the system or
51 with other threads in the same process that
52 were created with the
53 .B PTHREAD_SCOPE_SYSTEM
54 contention scope.
55 .PP
56 POSIX.1 requires that an implementation support at least one of these
57 contention scopes.
58 Linux supports
59 .BR PTHREAD_SCOPE_SYSTEM ,
60 but not
61 .BR PTHREAD_SCOPE_PROCESS .
62 .PP
63 On systems that support multiple contention scopes, then,
64 in order for the parameter setting made by
65 .BR pthread_attr_setscope ()
66 to have effect when calling
67 .BR pthread_create (3),
68 the caller must use
69 .BR pthread_attr_setinheritsched (3)
70 to set the inherit-scheduler attribute of the attributes object
71 .I attr
72 to
73 .BR PTHREAD_EXPLICIT_SCHED .
74 .PP
75 The
76 .BR pthread_attr_getscope ()
77 function returns the contention scope attribute of the
78 thread attributes object referred to by
79 .I attr
80 in the buffer pointed to by
81 .IR scope .
82 .SH RETURN VALUE
83 On success, these functions return 0;
84 on error, they return a nonzero error number.
85 .SH ERRORS
86 .BR pthread_attr_setscope ()
87 can fail with the following errors:
88 .TP
89 .B EINVAL
90 An invalid value was specified in
91 .IR scope .
92 .TP
93 .B ENOTSUP
94 .IR scope
95 specified the value
96 .BR PTHREAD_SCOPE_PROCESS ,
97 which is not supported on Linux.
98 .SH ATTRIBUTES
99 For an explanation of the terms used in this section, see
100 .BR attributes (7).
101 .ad l
102 .nh
103 .TS
104 allbox;
105 lbx lb lb
106 l l l.
107 Interface Attribute Value
108 T{
109 .BR pthread_attr_setscope (),
110 .BR pthread_attr_getscope ()
111 T} Thread safety MT-Safe
112 .TE
113 .hy
114 .ad
115 .sp 1
116 .SH CONFORMING TO
117 POSIX.1-2001, POSIX.1-2008.
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 .PP
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)