Sujet : Re: Futexes ain't fast
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.c++Date : 29. Aug 2024, 04:51:21
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vaor7n$3r4u5$1@raubtier-asyl.eternal-september.org>
References : 1 2
User-Agent : Mozilla Thunderbird
Am 28.08.2024 um 20:52 schrieb Chris M. Thomasson:
On 8/28/2024 5:09 AM, Bonita Montero wrote:
I tested the operating-system specific mutex (CRITICAL_SECTION Or
pthread_mutext_t) against a futex and a std::mutex. I guessed std::mutex
uses th operating system specific mutex internally, but the times varied
so much across Windows and Linux that I gues that std::mutex used at
least a differently parametrized operating system mutex or maybe even
completely own code.
This are the times and each line has a further contender:
[...]
while( futex.exchange( true, memory_order_acquire ) )
futex.wait( true, memory_order_relaxed );
futex.exchange( false, memory_order_release );
futex.notify_one();
} );
[...]
A wait bit would help out here... ;^) Afaict, this is a rather "naive" use of futexes. In you use case here, the exchange to unlock can be a simple atomic store with release semantics. Also, try to think about calling notify_* only when you absolutely need to... :^)
Show me your code ...