Sujet : Re: Futexes ain't fast
De : chris.m.thomasson.1 (at) *nospam* gmail.com (Chris M. Thomasson)
Groupes : comp.lang.c++Date : 29. Aug 2024, 21:12:32
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vaqkng$3vj5$2@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Mozilla Thunderbird
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!