Sets a processor affinity mask for the WASAPI client thread.
DWORD_PTR SetWasapiThreadAffinityMask(
DWORD_PTR dwThreadAffinityMask
)
dwThreadAffinityMask
Type: DWORD_PTR
[in] The affinity mask for the thread.
Type: DWORD_PTR
If the function succeeds, the return value is the thread’s previous affinity mask.
If the function fails, the return value is zero. If a WASAPI client thread is not already created, the function can only fail if the thread affinity mask does not match the process affinity mask.
A thread affinity mask is a bit vector in which each bit represents a logical processor that a thread is allowed to run on. A thread affinity mask must be a subset of the process affinity mask for the containing process of a thread. A thread can only run on the processors its process can run on. Therefore, the thread affinity mask cannot specify a 1 bit for a processor when the process affinity mask specifies a 0 bit for that processor.
Setting an affinity mask for a process or thread can result in threads receiving less processor time, as the system is restricted from running the threads on certain processors. In most cases, it is better to let the system select an available processor.
If the new thread affinity mask does not specify the processor that is currently running the thread, the thread is rescheduled on one of the allowable processors.
XAudio2 will implicitly set the mask to match its own, to override this call SetWasapiThreadAffinityMask after creating an XAudio2 instance.
Important Do not use the seventh processing core (logical core 6) for WASAPI thread affinity assignment. Because the seventh core’s time is governed by the hypervisor, the audio renderer might not receive enough time to complete processing for a frame, which can cause audio glitches.
Header: Declared in mmdeviceapi.h.
Library: Use MMDevApi.lib.