PTHREAD_ATTR_SETAFFINITY_NP(3)

NAME
pthread_attr_setaffinity_np, pthread_attr_getaffinity_np - set and get the thread's CPU affinity mask attribute

LIBRARY
libpthread

SYNOPSIS
#include <pthread.h>
#include <pthread_np.h>
int
pthread_attr_setaffinity_np(pthread_attr_t *attr, size_t cpusetsize, const cpu_set_t *mask);
int
pthread_attr_getaffinity_np(const pthread_attr_t *attr, size_t cpusetsize, cpu_set_t *mask);

DESCRIPTION
The pthread_attr_setaffinity_np() sets the CPU affinity mask of the attr to the value specified by the mask. The cpusetsize is the length (in bytes) of the data pointed to by mask. Normally this argument would be specified as sizeof(cpu_set_t). The threads created by pthread_create(3) with the attr will use the CPU affinity mask of the attr.

pthread_attr_getaffinity_np() writes the CPU affinity mask of the attr to the cpu_set_t structure pointed to by mask.

The cpu_set_t data structure represents a set of CPUs. See sched_setaffinity(2) for details.

RETURN VALUES
If successful, these functions will return zero. Otherwise an error number will be returned to indicate the error.

ERRORS
The pthread_attr_setaffinity_np() and pthread_attr_getaffinity_np() will fail if:

[EFAULT]
    The mask parameter is outside the process's allocated address space.

[EINVAL]
    The attr parameter is invalid.

[EPERM]
    The mask does not contain a valid CPU.

SEE ALSO
pthread_create(3), pthread_getaffinity_np(3), pthread_setaffinity_np(3)

HISTORY
The pthread_attr_setaffinity_np() and pthread_attr_getaffinity_np() functions first appeared in DragonFly 4.7.