Very limited shared promotion

Walter Bright newshound2 at digitalmars.com
Mon Jun 24 02:55:39 UTC 2019


On 6/23/2019 7:42 PM, Timon Gehr wrote:
> I really don't understand this "before" without memory barriers. Without memory 
> barriers, there is no "before". How to formalize this? What is it exactly that 
> "scope" guarantees?

The reference to shared i does not extend past the end of the function call. 
That doesn't mean the cached value of i is propagated to all other threads.

     int x;
     void fun(scope ref shared(int) x) {
         x = 3; // (*)
     } // end of reference to x is guaranteed
     assert(x == 3); // all caches not updated, assert is not guaranteed

(*) now replace this with a call to another thread to set x to 3.


More information about the Digitalmars-d mailing list