carb::thread::setAffinity

Defined in carb/thread/Util.h

inline bool carb::thread::setAffinity(NativeHandleType h, const CpuMaskVector &masks)

Sets the CPU Affinity for the thread.

On Windows each entry in the CpuMaskVector represents a Processor Group. Each thread can only belong to a single Processor Group, so this function will only set the CPU Affinity to the first non-zero entry in the provided CpuMaskVector. That is to say, if both masks[0] and masks[1] both have bits sets, only the CPUs in masks[0] will be set for the affinity.

On Linux, the CpuMaskVector is analagous to a cpu_set_t. There are no restrictions on the number of CPUs that the affinity mask can contain.

Parameters
  • h – The thread to set CPU Affinity for.

  • masks – Affinity masks to set.

Returns

True if the function succeeded, false otherwise. If masks is empty, or has no bits set, false will be returned. If the underlying function for setting affinity failed, then errno or last-error will be set.