comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Eachus <rieachus@comcast.net>
Subject: Re: Portable memory barrier?
Date: Sun, 7 May 2017 13:18:37 -0700 (PDT)
Date: 2017-05-07T13:18:37-07:00	[thread overview]
Message-ID: <0fc56bf7-1cfa-4776-9c47-a573db315c5f@googlegroups.com> (raw)
In-Reply-To: <e8d229c0-317e-4f5a-8d54-cf56c3aede7a@googlegroups.com>

On Friday, May 5, 2017 at 10:23:45 PM UTC-4, Jere wrote:
 
> Are there any Ada language constructs that can help?

No, but you don't need the help you think you need.  On modern, superscalar CPUs, you may have the assignment to the buffer and the index operation occurring as part of the same clock cycle.  Then the writes (to memory if memory locations are assigned) will occur in the order required by the ISA (for x86, what you require). For some RISC processors a fence will need to occur as part of that bundle of instructions, but trust the compiler for that.

If the read of the circular buffer is occurring possibly on a different CPU core which shares one or more cache levels, the instructions to make a location Volatile will be ignored by the CPU.  The compiler will mark the location, and the CPU will keep track of the type of memory, but Volatile does not cause writes to main memory. What will happen instead is that the cache coherency subsystem will insure that any accesses by CPU cores, GPUs, disk drives, or whatever will see a virtual location--which can move about--but all reads and writes will occur in sequence.

Didn't you ever wonder why modern CPUs have billions of transistors?  It is to keep things like this straight.  By the way, it can be the case that the first of two successive writes (with no intervening reads) will be eliminated, and/or additional reads may be added.  More to the point, if you cause an interrupt, the CPU will put that CPU core in some state consistent with memory.  Well, where a cache flush will create such a state in memory.  Without a cache flush, the CPU only cares that what it sees through the cache--and write pipes--is consistent.


  parent reply	other threads:[~2017-05-07 20:18 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-06  2:23 Portable memory barrier? Jere
2017-05-06  8:47 ` Jeffrey R. Carter
2017-05-06 14:17   ` Jere
2017-05-06 19:08     ` Dennis Lee Bieber
2017-05-06 19:26     ` Jeffrey R. Carter
2017-05-06 19:41     ` Jeffrey R. Carter
2017-05-06 20:42       ` Niklas Holsti
2017-05-09 19:49     ` Randy Brukardt
2017-05-09 22:07       ` Jere
2017-05-11  1:14         ` Randy Brukardt
2017-05-10 18:28       ` Shark8
2017-05-11  1:17         ` Randy Brukardt
2017-05-11 16:23           ` Jeffrey R. Carter
2017-05-07 20:18 ` Robert Eachus [this message]
2017-05-08  7:45   ` Dmitry A. Kazakov
2017-05-08 15:56     ` Robert Eachus
2017-05-08 16:22       ` Dmitry A. Kazakov
2017-05-08 18:39         ` Robert Eachus
2017-05-08 19:18         ` Robert Eachus
2017-05-08 21:09           ` Dmitry A. Kazakov
2017-05-08 23:24             ` Robert Eachus
2017-05-09  0:30               ` Jere
2017-05-09  4:02                 ` Robert Eachus
2017-05-09  4:32                 ` Robert Eachus
2017-05-09  4:44                   ` Robert Eachus
2017-05-09 22:26                   ` Jere
2017-05-09 20:01                 ` Randy Brukardt
2017-05-09 19:57               ` Randy Brukardt
2017-05-10  0:51                 ` Jere
2017-05-10  5:25                   ` J-P. Rosen
2017-05-10 22:56                     ` Jere
2017-05-11  7:36                       ` Dmitry A. Kazakov
2017-05-13 20:25                         ` Jere
2017-05-10  7:13                   ` Dmitry A. Kazakov
2017-05-10 16:45                     ` Robert Eachus
2017-05-10 17:28                       ` Simon Wright
2017-05-10 23:21                     ` Jere
2017-05-11  0:47                       ` Randy Brukardt
2017-05-13 20:11                         ` Jere
2017-05-15 22:33                           ` Randy Brukardt
2017-05-10 23:30                     ` Jere
2017-05-11  0:38                     ` Randy Brukardt
2017-05-10 16:38                   ` Jeffrey R. Carter
2017-05-10 23:40                     ` Jere
2017-05-10 16:19                 ` Robert Eachus
2017-05-11  1:02                   ` Randy Brukardt
2017-05-11  1:51                     ` Robert Eachus
2017-05-15 22:45                       ` Randy Brukardt
2017-05-08 20:29         ` Niklas Holsti
2017-05-08 21:09           ` Dmitry A. Kazakov
2017-05-09  4:34             ` Niklas Holsti
2017-05-09  6:16               ` Niklas Holsti
2017-05-09  8:34                 ` Dmitry A. Kazakov
2017-05-09 20:18                 ` Randy Brukardt
2017-05-09 20:10           ` Randy Brukardt
2017-05-09  0:05         ` Jere
2017-05-09  8:26           ` Dmitry A. Kazakov
2017-05-09 19:53         ` Randy Brukardt
2017-05-09 20:27           ` Dmitry A. Kazakov
2017-05-11  0:35             ` Randy Brukardt
2017-05-11  8:24               ` Dmitry A. Kazakov
2017-05-15 22:53                 ` Randy Brukardt
2017-05-18 17:44                   ` Dmitry A. Kazakov
2017-05-18 21:01                     ` Randy Brukardt
2017-05-19  7:54                       ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox