From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Portable memory barrier? Date: Sat, 6 May 2017 21:41:05 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <36434cd8-bc44-4d4a-957d-987fdf106be7@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 6 May 2017 19:37:51 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="17c34e22bbb4b36df9dffc77f5b469ac"; logging-data="18464"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mJ53sExqYj2Pa8r9AJi4ajgTkzSlGme0=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: <36434cd8-bc44-4d4a-957d-987fdf106be7@googlegroups.com> Cancel-Lock: sha1:1YoBIkZxn/xDaLSqzix9hnp1n/o= Xref: news.eternal-september.org comp.lang.ada:46689 Date: 2017-05-06T21:41:05+02:00 List-Id: On 05/06/2017 04:17 PM, Jere wrote: > > Side note: If I read it right, you seemed to indicate that volatile has nothing > to do with sequence. I'm no Ada expert, so I wanted to ask your interpretation > of section 16/3 of C.6. I'm used to C and C++ where if you have two volatile > variables being updated like this: > > Vol_Var_1 = 0; > Vol_Var_2 = 23; > > That the C and C++ standard guarantees the "compiler" will not reorder those two > statements. Note this says nothing about atomicness (which is only one reason > among others why Volatile is not sufficient for threading). It also doesn't > prevent the processor from reordering them. When I read that section in C.6 of > the RM, the verbage made me think Ada also prevented the compiler from > reordering the statements (again no relation to atomicness or CPU reordering). > > Is this not the case? Volatile is intended to guarantee that all reads and writes deal with the memory location directly. The idea is for things like memory-mapped H/W registers, where the H/W might change the value of the register or writing to the register causes the H/W to do something. This prevents optimizations that keep the value in a register for a while before writing it back to memory, for example, but not reordering the accesses to different variables IIUC. However, this is getting into the area where language lawyers are needed. -- Jeff Carter "[M]any were collected near them, ... to enjoy the sight of a dead young lady, nay, two dead young ladies, for it proved twice as fine as the first report." Persuasion 155