C++ Logo

std-proposals

Advanced search

Re: [std-proposals] volatile is not well supported

From: Phil Bouchard <boost_at_[hidden]>
Date: Fri, 2 Sep 2022 20:07:31 -0400
Ok thanks for the clarifications.


On 9/2/22 19:27, Jason McKesson via Std-Proposals wrote:
> On Fri, Sep 2, 2022 at 12:14 PM Phil Bouchard via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>>
>> On 9/1/22 19:37, Charles Milette via Std-Proposals wrote:
>>
>> I believe you want an atomic<shared_ptr<int>>, not volatile.
>>
>> Ok actually I don't need the variable to be atomic, I just need it to be reloaded.
> Reloaded for what purpose? If you're doing threading, then what you
> want is "atomic", not "volatile". Volatile has absolutely no special
> meaning with regard to inter-thread communication and offers no
> guarantee that what you see will represent what was written by some
> other thread at any point.
>
> Using `volatile` for inter-thread communication has a history in
> certain compilers, on certain CPUs, for many years. But those were the
> days when C++ didn't have a threaded memory model. Now that it does,
> we have a correct way that works on all compilers, on all CPUs they
> target.
>
> And that way is not spelled "volatile".
>
>> Also I wanted the entire struct to be volatile, not just a few fundamentals members.
> You can make the whole object atomic (assuming that it is trivially
> copyable). Though there may be a cost for doing atomic operations on
> objects larger than the size of a word or so.
-- 
Email Signature
Logo <https://www.fornux.com/>  
*Phil Bouchard*  facebook icon 
<https://www.linkedin.com/in/phil-bouchard-5723a910/>
CTO
T: (819) 328-4743
E: phil_at_[hidden]| www.fornux.com <http://www.fornux.com>
1188 rue Saint-Louis| Gatineau (Qc), J8T 2L8 Canada
Banner <https://goglobalawards.org/> Le message ci-dessus, ainsi que les 
documents l'accompagnant, sont destinés uniquement aux personnes 
identifiées et peuvent contenir des informations privilégiées, 
confidentielles ou ne pouvant être divulguées. Si vous avez reçu ce 
message par erreur, veuillez le détruire.
This communication (and/or the attachments) is intended for named 
recipients only and may contain privileged or confidential information 
which is not to be disclosed. If you received this communication by 
mistake please destroy all copies.

Received on 2022-09-03 00:07:33