OSDN Git Service

02f8bba5539edefe7782ce3ebc44afd28043140f
[linuxjm/LDP_man-pages.git] / original / man3 / pthread_attr_setscope.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .TH PTHREAD_ATTR_SETSCOPE 3 2014-04-21 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 pthread_attr_setscope, pthread_attr_getscope \- set/get contention scope
29 attribute in thread attributes object
30 .SH SYNOPSIS
31 .nf
32 .B #include <pthread.h>
33
34 .BI "int pthread_attr_setscope(pthread_attr_t *" attr \
35 ", int " scope );
36 .BI "int pthread_attr_getscope(pthread_attr_t *" attr \
37 ", int *" scope );
38 .sp
39 Compile and link with \fI\-pthread\fP.
40 .fi
41 .SH DESCRIPTION
42 The
43 .BR pthread_attr_setscope ()
44 function sets the contention scope attribute of the
45 thread attributes object referred to by
46 .I attr
47 to the value specified in
48 .IR scope .
49 The contention scope attribute defines the set of threads
50 against which a thread competes for resources such as the CPU.
51 POSIX.1-2001 specifies two possible values for
52 .IR scope :
53 .TP
54 .B PTHREAD_SCOPE_SYSTEM
55 The thread competes for resources with all other threads
56 in all processes on the system that are in the same scheduling
57 allocation domain (a group of one or more processors).
58 .B PTHREAD_SCOPE_SYSTEM
59 threads are scheduled relative to one another
60 according to their scheduling policy and priority.
61 .TP
62 .B PTHREAD_SCOPE_PROCESS
63 The thread competes for resources with all other threads
64 in the same process that were also created with the
65 .BR PTHREAD_SCOPE_PROCESS
66 contention scope.
67 .BR PTHREAD_SCOPE_PROCESS
68 threads are scheduled relative to other threads in the process
69 according to their scheduling policy and priority.
70 POSIX.1-2001 leaves it unspecified how these threads contend
71 with other threads in other process on the system or
72 with other threads in the same process that
73 were created with the
74 .B PTHREAD_SCOPE_SYSTEM
75 contention scope.
76 .PP
77 POSIX.1-2001 requires that an implementation support at least one of these
78 contention scopes.
79 Linux supports
80 .BR PTHREAD_SCOPE_SYSTEM ,
81 but not
82 .BR PTHREAD_SCOPE_PROCESS .
83
84 On systems that support multiple contention scopes, then,
85 in order for the parameter setting made by
86 .BR pthread_attr_setscope ()
87 to have effect when calling
88 .BR pthread_create (3),
89 the caller must use
90 .BR pthread_attr_setinheritsched (3)
91 to set the inherit-scheduler attribute of the attributes object
92 .I attr
93 to
94 .BR PTHREAD_EXPLICIT_SCHED .
95
96 The
97 .BR pthread_attr_getscope ()
98 function returns the contention scope attribute of the
99 thread attributes object referred to by
100 .I attr
101 in the buffer pointed to by
102 .IR scope .
103 .SH RETURN VALUE
104 On success, these functions return 0;
105 on error, they return a nonzero error number.
106 .SH ERRORS
107 .BR pthread_attr_setscope ()
108 can fail with the following errors:
109 .TP
110 .B EINVAL
111 An invalid value was specified in
112 .IR scope .
113 .TP
114 .B ENOTSUP
115 .IR scope
116 specified the value
117 .BR PTHREAD_SCOPE_PROCESS ,
118 which is not supported on Linux.
119 .SH ATTRIBUTES
120 .SS Multithreading (see pthreads(7))
121 The
122 .BR pthread_attr_setscope ()
123 and
124 .BR pthread_attr_getscope ()
125 functions are thread-safe.
126 .SH CONFORMING TO
127 POSIX.1-2001.
128 .SH NOTES
129 The
130 .B PTHREAD_SCOPE_SYSTEM
131 contention scope typically indicates that a user-space thread is
132 bound directly to a single kernel-scheduling entity.
133 This is the case on Linux for the obsolete LinuxThreads implementation
134 and the modern NPTL implementation,
135 which are both 1:1 threading implementations.
136
137 POSIX.1-2001 specifies that the default contention scope is
138 implementation-defined.
139 .SH SEE ALSO
140 .ad l
141 .nh
142 .BR pthread_attr_init (3),
143 .BR pthread_attr_setaffinity_np (3),
144 .BR pthread_attr_setinheritsched (3),
145 .BR pthread_attr_setschedparam (3),
146 .BR pthread_attr_setschedpolicy (3),
147 .BR pthread_create (3),
148 .BR pthreads (7)
149 .SH COLOPHON
150 This page is part of release 3.67 of the Linux
151 .I man-pages
152 project.
153 A description of the project,
154 information about reporting bugs,
155 and the latest version of this page,
156 can be found at
157 \%http://www.kernel.org/doc/man\-pages/.