| Deutsch English Français Italiano |
|
<vca4ph$31k12$5@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.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: Atomic caching of smart pointers Date: Mon, 16 Sep 2024 13:34:58 -0700 Organization: A noiseless patient Spider Lines: 25 Message-ID: <vca4ph$31k12$5@dont-email.me> References: <vc7ahq$2akr4$1@dont-email.me> <vc7f99$2atht$6@dont-email.me> <vc8hka$2mc93$1@dont-email.me> <vc9m1u$g3eq$2@gwaiyur.mb-net.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 16 Sep 2024 22:34:58 +0200 (CEST) Injection-Info: dont-email.me; posting-host="0f36da695d9f6b2ce32e431416f90f90"; logging-data="3199010"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4iZnESC//oaB377OjF1rJcD/oNW+P3vg=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:4ooFLkucsNxcKSBEgUYPZbMNyaU= In-Reply-To: <vc9m1u$g3eq$2@gwaiyur.mb-net.net> Content-Language: en-US Bytes: 2104 On 9/16/2024 9:23 AM, Marcel Mueller wrote: > Am 16.09.24 um 08:01 schrieb Paavo Helde: >> Meanwhile I think I found a bug in my posted code, I should probably >> use compare_exchange_strong() instead of compare_exchange_weak(). > > Indeed. With ..._weak you most likely need a loop. But if you already > have a loop for other purposes using the _weak function could avoid an > additional loop in the implementation of the function. The problem with weak is that it can spuriously fail. So, yup you need a loop. The strong one can be used for some older state machine algorithms I have seen. If a cas failed its simply because the comparands were different, not because of anything else... > >> I somehow thought the latter would err on the safe side, but it does >> not. In my test harness there seems to be no difference. > > On many platforms the underlying CAS primitives already are strong. In > this cases both function are identical. > > > Marcel