Very limited shared promotion

Manu turkeyman at gmail.com
Sat Jun 22 08:02:46 UTC 2019


On Sat, Jun 22, 2019 at 5:57 PM Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On 6/21/2019 5:26 PM, Manu wrote:
> > I've asked you 5 or 6 times to show how to pass a pointer to another thread
> > without violating scope.
> > Can you show it? You keep saying you can.
>
>      void foo(scope shared(int)* p) @trusted {
>          auto t = startThread();
>          passToThread(t, p);
>          waitForThreadToExit(t);
>      }

I don't believe `passToThread` could receive a `scope shared(int)*`...
can you show an implementation of passToThread?

> > You need an acquire fence before the function returns, it's trivial.
>
> That's right it is. But the compiler doesn't know you put one there, and scope
> does not cause it to be put there, and @safe does not, either.

There couldn't have been cross-thread communication if it was @safe.

> > If you want @safe expansion, that's future work, and I personally couldn't care
> > less about that work. I can create safe libraries with @trusted functions, and I
> > could do it _right now_.
>
> You're assuming semantics for scope and @safe that are not there, and so the
> compiler cannot assume them, either.

The compiler can assume that you didn't pass a scope value to another
thread, because it would be impossible to do.
Show how to do it? Your example above shows passToThread, but I'm just
going to ask you to show how that function works, and we'll recurse
until either the value reaches another thread, or you agree that scope
prevents a value from escaping...


More information about the Digitalmars-d mailing list