Unsynchronized int access from threads

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jun 18 22:15:25 UTC 2020


On Thu, Jun 18, 2020 at 03:07:54PM -0400, Steven Schveighoffer via Digitalmars-d wrote:
[...]
> Let's say a value is 0xffff0000
> 
> Thread that is looking for 0s reads the lower half of the number ->
> 0x????0000
> 
> Context switches, thread 2 writes 0x0000ffff into that memory slot.
> 
> Back at the zero-scanning thread, it reads the second half ->
> 0x0000????
> 
> Combines with the first part, and now it sees a 0 where there isn't
> one.
[...]

Hmmm very good point, hadn't thought of that. :-/  Oh well, I'll just
think of another way of parallelizing my code.  I think I can break the
work up into large enough chunks that the overhead of using traditional
synchronization primitives will be insignificant.

Thanks all for the replies!


T

-- 
A mathematician learns more and more about less and less, until he knows everything about nothing; whereas a philospher learns less and less about more and more, until he knows nothing about everything.


More information about the Digitalmars-d mailing list