Very limited shared promotion

Manu turkeyman at gmail.com
Fri Jun 21 08:17:29 UTC 2019


On Fri, Jun 21, 2019 at 5:55 PM Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On 6/19/2019 11:53 PM, Manu wrote:
> > Well, you're assuming that `fun()` is an unsafe function that did
> > violate the scope agreement and passed it out to worker threads.
>
> Not at all. Scope means it does not leak a reference that survives the end of
> the function. As long as the threads terminate before the function returns, it
> is valid code.

I agree it's 'theoretically' valid; that's why I suggested it and the
construct makes sense.
How would you write code that escapes the scope reference to another
thread? This must require some @trusted code to achieve sharing
between threads; at that point, the @trusted function is responsible
for re-instating the thread-locality guarantees (which are trivial to
implement). If you don't do @trusted mischief, there's no way to
migrate the value across threads, so your synchronisation issue
shouldn't exist if no @trusted code exists.


More information about the Digitalmars-d mailing list