OSDN Git Service

74d38656caf1d267bb3e2e0f58122468ba8f250f
[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 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .TH PTHREAD_ATTR_SETSCOPE 3 2008-10-24 "Linux" "Linux Programmer's Manual"
25 .SH NAME
26 pthread_attr_setscope, pthread_attr_getscope \- set/get contention scope
27 attribute in thread attributes object
28 .SH SYNOPSIS
29 .nf
30 .B #include <pthread.h>
31
32 .BI "int pthread_attr_setscope(pthread_attr_t *" attr \
33 ", int " scope );
34 .BI "int pthread_attr_getscope(pthread_attr_t *" attr \
35 ", int *" scope );
36 .sp
37 Compile and link with \fI\-pthread\fP.
38 .SH DESCRIPTION
39 The
40 .BR pthread_attr_setscope ()
41 function sets the contention scope attribute of the
42 thread attributes object referred to by
43 .I attr
44 to the value specified in
45 .IR scope .
46 The contention scope attribute defines the set of threads
47 against which a thread competes for resources such as the CPU.
48 POSIX.1-2001 specifies two possible values for
49 .IR scope :
50 .TP
51 .B PTHREAD_SCOPE_SYSTEM
52 The thread competes for resources with all other threads
53 in all processes on the system that are in the same scheduling
54 allocation domain (a group of one or more processors).
55 .B PTHREAD_SCOPE_SYSTEM
56 threads are scheduled relative to one another
57 according to their scheduling policy and priority.
58 .TP
59 .B PTHREAD_SCOPE_PROCESS
60 The thread competes for resources with all other threads
61 in the same process that were also created with the
62 .BR PTHREAD_SCOPE_PROCESS
63 contention scope.
64 .BR PTHREAD_SCOPE_PROCESS
65 threads are scheduled relative to other threads in the process
66 according to their scheduling policy and priority.
67 POSIX.1-2001 leaves it unspecified how these threads contend
68 with other threads in other process on the system or
69 with other threads in the same process that
70 were created with the
71 .B PTHREAD_SCOPE_SYSTEM
72 contention scope.
73 .PP
74 POSIX.1-2001 only requires that an implementation support one of these
75 contention scopes, but permits both to be supported.
76 Linux supports
77 .BR PTHREAD_SCOPE_SYSTEM ,
78 but not
79 .BR PTHREAD_SCOPE_PROCESS .
80
81 The
82 .BR pthread_attr_getscope ()
83 function returns the contention scope attribute of the
84 thread attributes object referred to by
85 .I attr
86 in the buffer pointed to by
87 .IR scope .
88 .SH RETURN VALUE
89 On success, these functions return 0;
90 on error, they return a nonzero error number.
91 .SH ERRORS
92 .BR pthread_attr_setscope ()
93 can fail with the following errors:
94 .TP
95 .B EINVAL
96 An invalid value was specified in
97 .IR scope .
98 .TP
99 .B ENOTSUP
100 .IR scope
101 specified the value
102 .BR PTHREAD_SCOPE_PROCESS ,
103 which is not supported on Linux.
104 .SH CONFORMING TO
105 POSIX.1-2001.
106 .SH NOTES
107 The
108 .B PTHREAD_SCOPE_SYSTEM
109 contention scope typically indicates that a userspace thread is
110 bound directly to a single kernel-scheduling entity.
111 This is the case on Linux for the obsolete LinuxThreads implementation
112 and the modern NPTL implementation,
113 which are both 1:1 threading implementations.
114
115 POSIX.1-2001 specifies that the default contention scope is
116 implementation-defined.
117 .SH SEE ALSO
118 .BR pthread_attr_init (3),
119 .BR pthread_attr_setaffinity_np (3),
120 .BR pthread_attr_setinheritsched (3),
121 .BR pthread_attr_setschedparam (3),
122 .BR pthread_attr_setschedpolicy (3),
123 .BR pthread_create (3),
124 .BR pthreads (7)