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 10:47:57 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 6 May 2017 08:44:41 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="7b5d89d32535da168706c052c4ddbf52"; logging-data="22264"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wkvrj9/PBu1brlup0tn0nvT6+XLq8ElU=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Cancel-Lock: sha1:wbnJ35NOZVxeBRMYXKBJFmzcxtE= Xref: news.eternal-september.org comp.lang.ada:46677 Date: 2017-05-06T10:47:57+02:00 List-Id: On 05/06/2017 04:23 AM, Jere wrote: > > In one procedure (Producer's Put procedure), I run into the situation where I > need to update the buffer, then the index (in that order) to ensure that the > consumer doesn't see the index change before the data is actually there. > > From a compiler optimization perspective, I believe I can tackle this with > the Volatile pragma/aspect. Assuming it works like it does in C, volatile > variables have to have their accesses in sequence. I think the RM also > reflects this [0]? Volatile means that something other than the program may change the value. It also means that all tasks of the program see the same sequence of updates. It does not mean that accesses are non-overlapping. If task A does I := I + 1; and task B does if I > 0 then with I marked Volatile, then A may update half of I, B read the partly updated value, and then A complete its update. Atomic means Volatile plus all access are sequential; in the example, if A begins to update I, B won't read it until A's update is complete. For your purposes, marking the (type of the) indices as Atomic should be all you need. -- 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