On Mon, Jan 23, 2023 at 11:38 AM Robert Engels <reng...@ix.netcom.com>
wrote:

> The atomic functions force a memory barrier when atomically in conjunction
> with the atomic read of the same value.
>
> You could use CGO to call a C function to do what you desire - but it
> shouldn’t be necessary.
>

C doesn't solve this problem, unless your "C function" is something like an
"asm volatile". C has the exact same underlying issue as Go here -- the
language does not define interprocess atomics, because doing so is hard.

In practice you can probably do the equivalent of a sequentially consistent
store on the writer side and a sequentially consistent read on the other,
and things will likely work.

With that said, that doesn't strictly work even for two C programs. As a
concrete example, if you're implementing sequentially consistent atomics on
x86, while read-modify-write instructions don't need any extra fencing, you
have to choose whether to make reads expensive (by adding a fence on reads)
or writes expensive (by adding a fence on writes). While in practice every
implementation chooses to make the writes expensive, that is an
implementation decision and nothing stops someone from making a
reads-expensive-writes-cheap compiler.

If a "writes cheap compiler" program does an atomic write over shared
memory to a "reads cheap compiler" program, there won't be any fences on
either side and you won't get sequential consistent synchronization.
(That's fine for a simple producer-consumer queue as in this example which
only requires release-acquire semantics, but fancier algorithms that rely
on sequential consistency will be quite unhappy.)


>
> Not sure what else I can tell you.
>
> On Jan 22, 2023, at 8:12 PM, Peter Rabbitson <ribasu...@gmail.com> wrote:
>
> 
> On Mon, Jan 23, 2023 at 12:42 AM robert engels <reng...@ix.netcom.com>
> wrote:
>
>> Write data to memory mapped file/shared memory. Keep track of last
>> written byte as new_length;
>>
>> Use atomic.StoreUint64(pointer to header.length, new_length);
>>
>>
> This does not answer the question I posed, which boils down to:
>
> How does one insert the equivalent of smp_wmb() /
> asm volatile("" ::: "memory") into a go program.
>
> For instance is any of these an answer?
> https://groups.google.com/g/golang-nuts/c/tnr0T_7tyDk/m/9T2BOvCkAQAJ
>
>
>> readers read ...
>>
>
> Please don't focus on the reader ;)
>
>
>> This assumes you are always appending ,,, then it is much more
>> complicated ... all readers have consumed the data before the writer reuses
>> it.
>>
>
> Yes, it is much more complicated :) I am making a note to post the result
> back to this thread in a few weeks when it is readable enough.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/5F73A3C7-32C3-42A1-91A2-E1A0714FAEA5%40ix.netcom.com
> <https://groups.google.com/d/msgid/golang-nuts/5F73A3C7-32C3-42A1-91A2-E1A0714FAEA5%40ix.netcom.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMbN1s5SAtWzgajE7ZCN_z-h2ABkQ5GWgx5%3DX7ehVQo-sOy82g%40mail.gmail.com.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to