carb::thread::setAffinity

Defined in carb/thread/Util.h

inline void carb::thread::setAffinity(NativeHandleType h, size_t mask)

Sets the CPU affinity for the given thread handle.

Each bit represents a logical CPU; bit 0 for CPU 0, bit 1 for CPU 1, etc.

Note

On Mac OS, the CPU affinity works differently than on other systems. The mask is treated as a unique ID for groups of threads that should run on the same core, rather than specific CPUs. For single CPU masks, this will function similarly to other systems (aside from the fact that the specific core the threads are running on being different).

Note

M1 Macs do not support thread affinity so this will do nothing on those systems.

Parameters
  • h – The native handle to the thread

  • mask – The bitmask representing the desired CPU affinity. Zero (no bits set) is ignored.