1pthread_attr_setscope(3)   Library Functions 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

LIBRARY

10       POSIX threads library (libpthread, -lpthread)
11

SYNOPSIS

13       #include <pthread.h>
14
15       int pthread_attr_setscope(pthread_attr_t *attr, int scope);
16       int pthread_attr_getscope(const pthread_attr_t *restrict attr,
17                                 int *restrict scope);
18

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

ATTRIBUTES

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

STANDARDS

83       POSIX.1-2008.
84

HISTORY

86       POSIX.1-2001.
87

NOTES

89       The PTHREAD_SCOPE_SYSTEM contention scope typically  indicates  that  a
90       user-space thread is bound directly to a single kernel-scheduling enti‐
91       ty.  This is the case on Linux for the obsolete LinuxThreads  implemen‐
92       tation and the modern NPTL implementation, which are both 1:1 threading
93       implementations.
94
95       POSIX.1 specifies that the default contention scope is  implementation-
96       defined.
97

SEE ALSO

99       pthread_attr_init(3), pthread_attr_setaffinity_np(3),
100       pthread_attr_setinheritsched(3), pthread_attr_setschedparam(3),
101       pthread_attr_setschedpolicy(3), pthread_create(3), pthreads(7)
102
103
104
105Linux man-pages 6.04              2023-03-30          pthread_attr_setscope(3)
Impressum