From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Portable memory barrier?
Date: Tue, 9 May 2017 14:53:57 -0500
Date: 2017-05-09T14:53:57-05:00 [thread overview]
Message-ID: <oet6ol$5gg$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: oeq60s$18c1$1@gioia.aioe.org
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:oeq60s$18c1$1@gioia.aioe.org...
> On 2017-05-08 17:56, Robert Eachus wrote:
>> One sentence summary: The CPU will play lots of tricks behind your
>> back, but in such a way you can pretend your code works as you intended.
>> (Er, after you get the bugs out.)
>>
>> On Monday, May 8, 2017 at 3:45:26 AM UTC-4, Dmitry A. Kazakov wrote:
>>
>>> I don't believe either of the sequences can get reordered by the CPU,
>>> but it is only belief and common sense.
>>
>> Silly rabbit, Trix are for kids. Oops, silly programmer, common
>> sense has nothing to do with modern CPUs.
> [...]
>> Is any of this important to a high-level language programmer? Not
>> really, unless they are working in hard real time. (Which I did.) If you
>> program in assembler, or more likely work on a compiler back-end,
>> knowing which instructions fit together is important. Even more
>> important is coding so that an instruction that references a new cache
>> line in memory is followed by as many instructions as possible that
>> don't use that value. Some times you run into cases where you want to
>> take advantage of write combining or some other trick involving the
>> write pipe--but today, smart compiler optimization is about accesses to
>> main memory and not much else.
>
> I don't see anything there what would prevent CPU from changing the order
> of accesses to two *independent* memory locations when only the program
> logic ties them nothing else. Well, except that there is no obvious reason
> why it would like to change that order.
>
> Wikipedia provides a more simple example of the problem:
>
> https://en.wikipedia.org/wiki/Memory_barrier
>
> The case of a lock-free FIFO is different because it involves index and
> array element.
>
> For practical use when the buffer size is > 1 there cannot be any problem.
>
> Yet the question stands. In particular, which Ada primitives may ensure
> safe implementations of lock-free structures when no protected objects
> used.
Atomic objects make such a guarentee. Nothing else does (well, ignoring
protected objects, of course, since you excluded them). End of story.
(Except that compilers might not implement it right, as I noted before.)
Randy.
next prev parent reply other threads:[~2017-05-09 19:53 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
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 [this message]
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