]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/pthread_attr_setscope.3
bc49fd1366f7cbd50cbe5a9c33d8caa2cb605c28
[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 LIBRARY
11 POSIX threads library
12 .RI ( libpthread ", " \-lpthread )
13 .SH SYNOPSIS
14 .nf
15 .B #include <pthread.h>
16 .PP
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 .BR PTHREAD_SCOPE_PROCESS
46 contention scope.
47 .BR 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 .PP
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 .PP
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 .PP
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 .IR 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 .ad l
103 .nh
104 .TS
105 allbox;
106 lbx lb lb
107 l l l.
108 Interface Attribute Value
109 T{
110 .BR pthread_attr_setscope (),
111 .BR pthread_attr_getscope ()
112 T} Thread safety MT-Safe
113 .TE
114 .hy
115 .ad
116 .sp 1
117 .SH CONFORMING TO
118 POSIX.1-2001, POSIX.1-2008.
119 .SH NOTES
120 The
121 .B PTHREAD_SCOPE_SYSTEM
122 contention scope typically indicates that a user-space thread is
123 bound directly to a single kernel-scheduling entity.
124 This is the case on Linux for the obsolete LinuxThreads implementation
125 and the modern NPTL implementation,
126 which are both 1:1 threading implementations.
127 .PP
128 POSIX.1 specifies that the default contention scope is
129 implementation-defined.
130 .SH SEE ALSO
131 .ad l
132 .nh
133 .BR pthread_attr_init (3),
134 .BR pthread_attr_setaffinity_np (3),
135 .BR pthread_attr_setinheritsched (3),
136 .BR pthread_attr_setschedparam (3),
137 .BR pthread_attr_setschedpolicy (3),
138 .BR pthread_create (3),
139 .BR pthreads (7)