Very limited shared promotion

Walter Bright newshound2 at digitalmars.com
Fri Jun 21 23:35:22 UTC 2019


On 6/21/2019 5:07 AM, Manu wrote:
> There is no "between threads" unless you have already entered @trusted land.
> The reason for my proposal in the OP is precisely to prevent passing
> data to other threads, that's the key that makes this promotion safe.

Scope doesn't do that. I keep saying this. But the premise is strange, anyway, 
as why would you want to convert a reference to shared if not to bass it to 
another thread?


> Can you show how you managed to get a ref to another thread without
> entering @trusted?
There's no such thing as a ref to another thread. You can pass a ref to another 
thread in a scope function, as long as the ref doesn't survive the scope of foo().

The compiler cannot check that, though, and so cannot bless the implicit 
conversion to shared. I've said this 4 or 5 times now.


> There's no possibility of the synchronisation
> issue arising unless there's some way to escape a scope ref to another
> thread, which scope prevents.

You're inventing semantics for scope that I've repeatedly told you are not there.


> We're not talking about atomic reads here, we're talking about memory barriers.

I recommend watching:

https://www.youtube.com/watch?v=A8eCGOqgvH4
https://www.youtube.com/watch?v=KeLBd2EJLOU

as you and I are not speaking the same language. In particular the sections on 
how atomics create sequentially consistent data-race-free reads and writes of 
variables. Not needing to read x atomically after foo() ends is just plain wrong.


More information about the Digitalmars-d mailing list