Sujet : Re: Futexes ain't fast
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.c++Date : 30. Aug 2024, 17:47:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vast3j$imrm$1@raubtier-asyl.eternal-september.org>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
Am 29.08.2024 um 22:12 schrieb Chris M. Thomasson:
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 ); };
#elif defined(__unix__)
sem_t sem;
sem_init( &sem, 0, 0 );
auto acquire = [&] { while( sem_wait( &sem ) == EINTR ); };
[...]
Nice touch with the EINTR. I have seen a lot of code that misses this aspect... Yikes!
Signals are really sick.