1PTHREAD_ATTR_SETSCOPE(3)   Linux Programmer's Manual  PTHREAD_ATTR_SETSCOPE(3)
2
3
4

NAME

6       pthread_attr_setscope, pthread_attr_getscope - set/get contention scope
7       attribute in thread attributes object
8

SYNOPSIS

10       #include <pthread.h>
11
12       int pthread_attr_setscope(pthread_attr_t *attr, int scope);
13       int pthread_attr_getscope(const pthread_attr_t *attr, int *scope);
14
15       Compile and link with -pthread.
16

DESCRIPTION

18       The pthread_attr_setscope() function sets the contention  scope  attri‐
19       bute  of  the thread attributes object referred to by attr to the value
20       specified in scope.  The contention scope attribute defines the set  of
21       threads  against which a thread competes for resources such as the CPU.
22       POSIX.1 specifies two possible values for scope:
23
24       PTHREAD_SCOPE_SYSTEM
25              The thread competes for resources with all other threads in  all
26              processes  on the system that are in the same scheduling alloca‐
27              tion   domain   (a   group   of   one   or   more   processors).
28              PTHREAD_SCOPE_SYSTEM  threads  are scheduled relative to one an‐
29              other according to their scheduling policy and priority.
30
31       PTHREAD_SCOPE_PROCESS
32              The thread competes for resources with all other threads in  the
33              same    process    that    were    also    created    with   the
34              PTHREAD_SCOPE_PROCESS contention  scope.   PTHREAD_SCOPE_PROCESS
35              threads  are  scheduled relative to other threads in the process
36              according to their  scheduling  policy  and  priority.   POSIX.1
37              leaves  it  unspecified  how  these  threads  contend with other
38              threads in other process on the system or with other threads  in
39              the same process that were created with the PTHREAD_SCOPE_SYSTEM
40              contention scope.
41
42       POSIX.1 requires that an implementation support at least one  of  these
43       contention   scopes.   Linux  supports  PTHREAD_SCOPE_SYSTEM,  but  not
44       PTHREAD_SCOPE_PROCESS.
45
46       On systems that support multiple contention scopes, then, in order  for
47       the  parameter  setting  made by pthread_attr_setscope() to have effect
48       when calling pthread_create(3), the caller must  use  pthread_attr_set‐
49       inheritsched(3)  to  set  the  inherit-scheduler  attribute  of the at‐
50       tributes object attr to PTHREAD_EXPLICIT_SCHED.
51
52       The pthread_attr_getscope() function returns the contention  scope  at‐
53       tribute of the thread attributes object referred to by attr in the buf‐
54       fer pointed to by scope.
55

RETURN VALUE

57       On success, these functions return 0; on error, they return  a  nonzero
58       error number.
59

ERRORS

61       pthread_attr_setscope() can fail with the following errors:
62
63       EINVAL An invalid value was specified in scope.
64
65       ENOTSUP
66              scope  specified  the  value PTHREAD_SCOPE_PROCESS, which is not
67              supported on Linux.
68

ATTRIBUTES

70       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
71       tributes(7).
72
73       ┌─────────────────────────┬───────────────┬─────────┐
74Interface                Attribute     Value   
75       ├─────────────────────────┼───────────────┼─────────┤
76pthread_attr_setscope(), │ Thread safety │ MT-Safe │
77pthread_attr_getscope()  │               │         │
78       └─────────────────────────┴───────────────┴─────────┘

CONFORMING TO

80       POSIX.1-2001, POSIX.1-2008.
81

NOTES

83       The PTHREAD_SCOPE_SYSTEM contention scope typically  indicates  that  a
84       user-space  thread  is bound directly to a single kernel-scheduling en‐
85       tity.  This is the case on Linux for the obsolete  LinuxThreads  imple‐
86       mentation  and  the  modern  NPTL  implementation,  which  are both 1:1
87       threading implementations.
88
89       POSIX.1 specifies that the default contention scope is  implementation-
90       defined.
91

SEE ALSO

93       pthread_attr_init(3), pthread_attr_setaffinity_np(3),
94       pthread_attr_setinheritsched(3), pthread_attr_setschedparam(3),
95       pthread_attr_setschedpolicy(3), pthread_create(3), pthreads(7)
96

COLOPHON

98       This page is part of release 5.10 of the Linux man-pages project.  A
99       description of the project, information about reporting bugs, and the
100       latest version of this page, can be found at
101       https://www.kernel.org/doc/man-pages/.
102
103
104
105Linux                             2017-09-15          PTHREAD_ATTR_SETSCOPE(3)
Impressum