You have hit on false sharing. No update will be lost.... but, it will be
slow. Both threads will race. One will win. The other will wait. This
contention is the source of a lot of missed opportunity.

As is the case a lot of the time, my good friend Martin is much better
about explaining it.

https://mechanical-sympathy.blogspot.com/2011/07/false-sharing.html

On Sun, May 28, 2017 at 9:36 PM, Peter Veentjer <alarmnum...@gmail.com>
wrote:

> Thanks Todd.
>
> Ok, that makes sense.
>
> A related question. What happens if 2 threads do a plain write in the same
> cache line but independent locations.
>
> If this happens concurrently, can the system run into a 'lost update'? I'm
> sure it can't and I guess the cache coherence protocol takes care it. But
> would like to get confirmation anyway.
>
>
> On Monday, May 29, 2017 at 6:17:33 AM UTC+3, Peter Veentjer wrote:
>>
>> In Martin Thompson's talks about Aeron he mentions writing threads doing
>> an increment on an AtomicLong counter to claim a region in a buffer, but
>> the initial 4 bytes  for the length field aren't written, but only on
>> completion of the frame, the length is set. This signals to the reader of
>> the buffer that this particular write is complete and provides a happens
>> before relation.
>>
>> My question is about this length field; who is responsible for zero'ing
>> it out? Once the buffer has been written, the content could be total
>> gibberish and if it isn't zero'd, the reading thread could falsely assume
>> it is written and boom..
>>
> --
> You received this message because you are subscribed to the Google Groups
> "mechanical-sympathy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mechanical-sympathy+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mechanical-sympathy+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to