When setting the Windows CPU affinity mask for Core 2, is the mask supposed to be 0x0010 or 0x0001? I have seen an example where the mask was set to 0x0010 for Core 0 but this didn't make much sense?
Asked
Active
Viewed 1,037 times
0
-
Why doesn't that make sense? If it's a bitmask, 0x0001 makes perfect sense, it sets bit 0 to 1. – Lasse V. Karlsen Aug 02 '14 at 15:58
-
@LasseV.Karlsen because 0000 for Core....0 makes more sense? – user3811839 Aug 02 '14 at 16:04
-
1If it's a bitmask, that would make no cores eligible. So no, it doesn't make more sense (to me). It's not the number of the core, it's a bitmask of which cores you allow. – Lasse V. Karlsen Aug 02 '14 at 16:05
-
Remember, this is a mask, not an enumeration. If 0000 means Core 0 only, how would you say "Both core 0 and core 1"? – Raymond Chen Aug 02 '14 at 17:40
-
possible duplicate of [Example usage of SetProcessAffinityMask in C/C++?](http://stackoverflow.com/questions/12803585/example-usage-of-setprocessaffinitymask-in-c-c) – Raymond Chen Aug 02 '14 at 17:43
2 Answers
1
0x0000
allows no CPUs to be scheduled for this process/thread at all. (it will be suspended, assuming setting the affinity doesn't fail during parameter validation, which might be different on different Windows versions)
0x0001
allows Core 0, only
0x0002
allows Core 1, only
0x0003
allows both Core 0 and Core 1.

Ben Voigt
- 277,958
- 43
- 419
- 720
-
Is affinity 0x0 really supported? I tried under Windows 7 and the call fails with error 87 (ERROR_INVALID_PARAMETER). – Roland Pihlakas Sep 05 '16 at 19:28
-
I tried using NtSetInformationProcess with ProcessAffinityMask and reference to value 0x0 but that too fails with 0xC000000D (STATUS_INVALID_PARAMETER). – Roland Pihlakas Sep 05 '16 at 22:02
-
@RolandPihlakas: Please read more carefully: *assuming setting the affinity doesn't fail during parameter validation, which might be different on different Windows versions* – Ben Voigt Sep 05 '16 at 22:34
-
Thanks for the details! Do You happen to remember on which Windows version affinity 0x0 did pass the parameter validation? – Roland Pihlakas Sep 06 '16 at 11:58
-
@RolandPihlakas: I don't know if there are any such versions at all, but the official documentation for the affinity functions doesn't promise that `0x0000` is always rejected as an invalid parameter, so you shouldn't rely on it. – Ben Voigt Sep 06 '16 at 14:01