bool Associative Array Synchronized

Chris Williams yoreanon-chrisw at yahoo.co.jp
Thu Mar 20 11:39:10 PDT 2014


On Thursday, 20 March 2014 at 18:06:18 UTC, Etienne wrote:
> Right, I was assuming it was always ordered, but modern 
> processor pipelines are different I guess.

Even without rearranging the order of your code, your bit exists 
in RAM but all the logic takes place in a CPU register, meaning 
that any time you operate with the bit, there's at least two 
copies. When the CPU switches threads (which could be at any 
point), it empties the CPU into RAM. If the thread it's switching 
to then tries to interact with the bit, it's going to create a 
third copy. Now whichever of the two threads is slower to write 
back to the original location is going to smash the other's.


More information about the Digitalmars-d-learn mailing list