Sujet : Re: Futexes ain't fast
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.c++Date : 29. Aug 2024, 20:45:15
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vaqj48$3kmh$2@raubtier-asyl.eternal-september.org>
References : 1 2 3 4 5 6 7 8
User-Agent : Mozilla Thunderbird
Am 29.08.2024 um 21:27 schrieb Chris M. Thomasson:
On 8/29/2024 12:25 PM, Chris M. Thomasson wrote:
On 8/29/2024 4:03 AM, Bonita Montero wrote:
Am 29.08.2024 um 06:18 schrieb Chris M. Thomasson:
On 8/28/2024 9:17 PM, Chris M. Thomasson wrote:
On 8/28/2024 8:51 PM, Bonita Montero wrote:
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 ...
>
>
I did a while back for a futex mutex, win32 impl iirc... Do I have to find the older code?
>
Lets see... It's a bit hard to find for some reason:
>
https://groups.google.com/g/comp.lang.c++/c/1MZvhswJ6DQ/m/qyaYH-i0CgAJ
>
This includes your futex:
>
os-mutex C++-futex CT-Futex std::mutex
1 4.458 5.288 2.932 6.213
[...]
23 1016.16 2828.65 905.289 2798.37
24 1096.64 2919.04 946.814 2914.23
25 1161.21 3052.88 996.146 3093
26 1256.53 3094.02 1034.94 3220.38
27 1379.79 3323.04 1079.41 3390.07
28 1446.68 3533.71 1106.27 3516.21
29 1514.12 3618.5 1160 3624.3
30 1601.25 3761.2 1218.03 3765.6
31 1673.59 3913.48 1259.65 3947.46
32 1827.81 4134.67 1319.16 4061.73
>
The futex mutex seems to scale a little better...? 1319.16 v 1827.81 for os mutex?
>
32 means 32 threads, right wrt hc in your code?
Yes, AMD 7950X 16-core CPU.