1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .TH PTHREAD_ATTR_SETAFFINITY_NP 3 2010-09-10 "Linux" "Linux Programmer's Manual"
26 pthread_attr_setaffinity_np, pthread_attr_getaffinity_np \- set/get
27 CPU affinity attribute in thread attributes object
30 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
31 .B #include <pthread.h>
33 .BI "int pthread_attr_setaffinity_np(pthread_attr_t *" attr ,
34 .BI " size_t " cpusetsize ", const cpu_set_t *" cpuset );
35 .BI "int pthread_attr_getaffinity_np(pthread_attr_t *" attr ,
36 .BI " size_t " cpusetsize ", cpu_set_t *" cpuset );
38 Compile and link with \fI\-pthread\fP.
42 .BR pthread_attr_setaffinity_np ()
44 sets the CPU affinity mask attribute of the
45 thread attributes object referred to by
47 to the value specified in
49 This attribute determines the CPU affinity mask
50 of a thread created using the thread attributes object
54 .BR pthread_attr_getaffinity_np ()
56 returns the CPU affinity mask attribute of the thread attributes object
59 in the buffer pointed to by
64 is the length (in bytes) of the buffer pointed to by
66 Typically, this argument would be specified as
67 .IR sizeof(cpu_set_t) .
69 For more details on CPU affinity masks, see
70 .BR sched_setaffinity (2).
71 For a description of a set of macros
72 that can be used to manipulate and inspect CPU sets, see
75 On success, these functions return 0;
76 on error, they return a nonzero error number.
80 .RB ( pthread_attr_setaffinity_np ())
82 specified a CPU that was outside the set supported by the kernel.
83 (The kernel configuration option
85 defines the range of the set supported by the kernel data type
87 used to represent CPU sets.)
88 .\" The raw sched_getaffinity() system call returns the size (in bytes)
89 .\" of the cpumask_t type.
92 .RB ( pthread_attr_getaffinity_np ())
93 A CPU in the affinity mask of the thread attributes object referred to by
95 lies outside the range specified by
98 .IR cpuset / cpusetsize
102 .RB ( pthread_attr_setaffinity_np ())
103 Could not allocate memory.
105 These functions are provided by glibc since version 2.3.4.
107 These functions are nonstandard GNU extensions;
108 hence the suffix "_np" (nonportable) in the names.
111 versions of these functions were provided that did not have a
114 Instead the CPU set size given to the underlying system calls was always
115 .IR sizeof(cpu_set_t) .
117 .BR sched_setaffinity (2),
118 .BR pthread_attr_init (3),
119 .BR pthread_setaffinity_np (3),