#### POSIX Threads for Windows – REFERENCE - pthreads-win32

Reference Index

Table of Contents

## Name

Operations on CPU affinity sets:

CPU_EQUAL - test equality of two sets

CPU_ZERO - clear all CPUs from set

CPU_SET - set a specified CPU in a set

CPU_CLR - unset a specified CPU in a set

CPU_ISSET - test if a specified CPU in a set is set

CPU_COUNT - return the number of CPUs currently set

CPU_AND - obtain the intersection of two sets

CPU_OR - obtain the union of two sets

CPU_XOR - obtain the mutually excluded set

## Synopsis

#include <sched.h>

int CPU_EQUAL(cpu_set_t * set1, cpu_set_t * set2);

void CPU_ZERO(cpu_set_t * set);

void CPU_SET(int cpu, cpu_set_t * set);

void CPU_CLR(int cpu, cpu_set_t * set);

int CPU_ISSET(int cpu, cpu_set_t * set);

int CPU_COUNT(cpu_set_t * set);

void CPU_AND(cpu_set_t * destset, cpu_set_t * srcset1, cpu_set_t * srcset2);

void CPU_OR(cpu_set_t * destset, cpu_set_t * srcset1, cpu_set_t * srcset2);

void CPU_XOR(cpu_set_t * destset, cpu_set_t * srcset1, cpu_set_t * srcset2);

## Description

The cpu_set_t data structure represents a set of CPUs. CPU sets are used by sched_setaffinity() and pthread_setaffinity_np(), etc.

The cpu_set_t data type is implemented as a bitset. However, the data structure is considered opaque: all manipulation of CPU sets should be done via the macros described in this page.

The following macros are provided to operate on the CPU set set:

CPU_ZERO Clears set, so that it contains no CPUs.

CPU_SET Add CPU cpu to set.

CPU_CLR Remove CPU cpu from set.

CPU_ISSET Test to see if CPU cpu is a member of set.

CPU_COUNT Return the number of CPUs in set.

Where a cpu argument is specified, it should not produce side effects, since the above macros may evaluate the argument more than once.

The first available CPU on the system corresponds to a cpu value of 0, the next CPU corresponds to a cpu value of 1, and so on.

The following macros perform logical operations on CPU sets:

CPU_AND Store the intersection of the sets srcset1 and srcset2 in destset (which may be one of the source sets).

CPU_OR Store the union of the sets srcset1 and srcset2 in destset (which may be one of the source sets).

CPU_XOR Store the XOR of the sets srcset1 and srcset2 in destset (which may be one of the source sets). The XOR means the set of CPUs that are in either srcset1 or srcset2, but not both.

CPU_EQUAL Test whether two CPU set contain exactly the same CPUs.

## Return Value

These macros either return a value consistent with the operation or nothing.

## Errors

These macros do not return an error status.

## See Also

sched_getaffinity(3) , sched_setaffinity(3) , pthread_setaffininty_np(3) , pthread_getaffinity_np(3) .

Table of Contents

- Name

- Synopsis

- Description

- Return Value

- Errors

- See Also

####