Manages a set of CPU indices to which a thread may be bound.
ThreadAffinity is a value-semantic type that represents a CPU affinity mask. It abstracts away the platform-specific details of cpu_set_t (Linux) and processor-group bitmasks (Windows).
Linux
Backed by a cpu_set_t. Supports CPU indices in the range [0, CPU_SETSIZE) (typically 0-1023). The native_handle() accessor provides a const cpu_set_t& for direct use with pthread_setaffinity_np or sched_setaffinity.
Windows
Backed by a 64-bit bitmask plus a processor group index (WORD). Windows organises logical processors into groups of up to 64. This class supports a single group at a time: the group is determined by the first CPU added via add_cpu(). Subsequent calls to add_cpu() for CPUs that belong to a different group are silently ignored. Use get_group() and get_mask() to retrieve the platform-native values for SetThreadGroupAffinity.
Thread safety
None. ThreadAffinity is a plain value type with no internal synchronisation. Concurrent reads are safe; concurrent mutation (or a read concurrent with a write) requires external locking.
Copyability / movability
Implicitly copyable and movable (compiler-generated special members).
- Warning
- On Windows, CPUs from different processor groups cannot be combined in a single ThreadAffinity instance. If you need cross-group affinity you must apply separate ThreadAffinity objects per group.
Definition at line 206 of file scheduler_policy.hpp.