Sujet : Re: Futexes ain't fast
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.c++Date : 29. Aug 2024, 12:03:03
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vapkh5$3ukli$1@raubtier-asyl.eternal-september.org>
References : 1 2 3 4 5
User-Agent : Mozilla Thunderbird
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
2 14.607 42.9285 33.8295 13.057
3 31.3747 119.928 78.9007 29.7953
4 48.9462 236.334 156.169 38.9327
5 78.7644 401.246 208.919 105.873
6 121.046 652.817 312.418 92.4637
7 229.815 834.371 374.232 176.73
8 228.219 934.64 457.591 294.029
9 428.12 1162.23 465.212 470.136
10 437.309 1244.29 526.45 326.618
11 248.07 1379.83 559.527 550.964
12 319.084 1560.5 532.445 551.784
13 370.088 1644.48 558.57 883.909
14 420.677 1719.65 609.394 1101.48
15 505.628 1884.92 648.361 1288.54
16 538.861 2029.97 670.726 1479.45
17 556.539 2056.18 676.595 1602.34
18 658.829 2205.71 731.472 1958.6
19 673.713 2351.46 771.112 2003.13
20 767.112 2430.94 794.487 2151.04
21 827.977 2549.65 801.974 2443.2
22 917.694 2679.09 881.514 2551.47
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