Sujet : Re: Futexes ain't fast
De : chris.m.thomasson.1 (at) *nospam* gmail.com (Chris M. Thomasson)
Groupes : comp.lang.c++Date : 19. Sep 2024, 21:50:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vci2ql$n443$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
On 8/29/2024 12:20 PM, Chris M. Thomasson wrote:
On 8/29/2024 7:30 AM, Bonita Montero wrote:
This is by far the fastest code:
>
#if defined(_WIN32)
HANDLE hSem = CreateSemaphoreA( nullptr, 0, 0x7FFFFFFF, nullptr );
auto acquire = [&] { WaitForSingleObject( hSem, INFINITE ); };
auto release = [&] { ReleaseSemaphore( hSem, 1, nullptr ); };
^^^^^^^^^^^^^^^^^^^^^^
Actually, release can be SetEvent because the mutex logic only needs a binary semaphore, or an event on windows. However, I cannot remember if an event is "faster" than a semaphore on windows or not. Still do not know how windows handles it's futexes wrt internal impl. WaitOnAddress and such.
[...]
Not sure if you are familiar with them, but I do remember a special type of event on Windows in the kernel. Iirc, they were called keyed events. Still not sure how Windows implements WaitOnAddress.