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:26:39 +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:23:25 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="17c34e22bbb4b36df9dffc77f5b469ac"; logging-data="15545"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+udMRLJIFMqRrH4etw1SEpebIqNLEMEq4=" 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:lLGkdMRCKWF0fEAWrGnk4bgDx54= Xref: news.eternal-september.org comp.lang.ada:46688 Date: 2017-05-06T21:26:39+02:00 List-Id: On 05/06/2017 04:17 PM, Jere wrote: > > Assuming the indexes are atomic and volatile, then I am not worried about > partial writes to the indexes. I"m more worried about some architectures that > allow for instruction reordering. What I don't want to happen is in Task A that > the store to My_Array happens after the update to the Put_Index. If that > happens, then there are cases where Task B verifies the buffer isn't empty and > tries to access the array but Task A hasn't gotten around to updating the array > because the CPU decided to rearrange the stores. Yes, Ada, having had tasking since the beginning, has ways to deal with this. They involve grouping the index increment and the array assignment together into a single thing that is atomic with respect to the index read. This is called a "critical region" in CS, and is usually a protected operation in Ada, although one could also use a suspension object or machine-code insertion. -- 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