int
pthread_setaffinity_np(
pthread_t thread
, size_t size
, cpuset_t *set
)
int
pthread_getaffinity_np(
pthread_t thread
, size_t size
, cpuset_t *set
)
pthread_setaffinity_np()
function sets the affinity mask
set
for
thread
.
At least one valid CPU must be set in the mask.
The
pthread_getaffinity_np()
function gets the affinity mask of
thread
into
set
.
Note that
set
must be created and initialized using the
cpuset(3)
functions.
)
and
pthread_getaffinity_np(
)
functions return 0 on success.
Otherwise, an error number is returned to indicate the error.
cpuset_t *cset;
pthread_t pth;
cpuid_t ci;
cset = cpuset_create();
if (cset == NULL) {
err(EXIT_FAILURE, "cpuset_create");
}
ci = 0;
cpuset_set(ci, cset);
pth = pthread_self();
error = pthread_setaffinity_np(pth, cpuset_size(cset), cset);
if (error) {
...
}
cpuset_destroy(cset);
)
and
pthread_getaffinity_np(
)
functions fail if:
EINVAL
]
set
was invalid.
EPERM
]
ESRCH
]
thread
.