Jinoh Kang (@iamahuman) commented about dlls/ntdll/heap.c:
NtCurrentTeb()->HeapVirtualAffinity = affinity;
- }
- affinity %= ARRAY_SIZE(category->affinity_group);
- /* acquire a group, the thread will own it and no other thread can clear free bits.
* some other thread might still set the free bits if they are freeing blocks.
*/
- if (!(group = heap_acquire_category_group( heap, flags, block_size, category ))) return NULL;
- /* serialize with heap_free_block_lfh: atomically set GROUP_FLAG_FREE when the free bits are all 0. */
- if (group_find_free_block( group, block_size, &block ))
InterlockedAnd( &group->free_bits, ~GROUP_FLAG_FREE );
- else
InterlockedCompareExchange( &group->free_bits, GROUP_FLAG_FREE, 0 );
- /* if GROUP_FLAG_FREE was set, thread released its ownership. */
This comment is misleading since the current thread relinquishes ownership of the group in either case. Note that, in the current design, a thread does not own its affinity group; the group slot can be shared with arbitrary number of threads.