| Deutsch English Français Italiano |
|
<vaqhud$2r8p$8@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> Newsgroups: comp.lang.c++ Subject: Re: Futexes ain't fast Date: Thu, 29 Aug 2024 12:25:01 -0700 Organization: A noiseless patient Spider Lines: 58 Message-ID: <vaqhud$2r8p$8@dont-email.me> References: <van414$3fe9t$1@raubtier-asyl.eternal-september.org> <vanrkt$3j1oq$1@dont-email.me> <vaor7n$3r4u5$1@raubtier-asyl.eternal-september.org> <vaosod$3ra5a$2@dont-email.me> <vaosr5$3ra5a$3@dont-email.me> <vapkh5$3ukli$1@raubtier-asyl.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 29 Aug 2024 21:25:02 +0200 (CEST) Injection-Info: dont-email.me; posting-host="98c6004928f46df0abe90729ccf8af51"; logging-data="93465"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MpHDXfaQPwRdnt4FiFzkZ6oZM+jGxn+M=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:1fIhpSuxYrqiV0/Vtse9grROtuo= In-Reply-To: <vapkh5$3ukli$1@raubtier-asyl.eternal-september.org> Content-Language: en-US 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?