Very limited shared promotion

Manu turkeyman at gmail.com
Wed Jun 19 03:00:46 UTC 2019


On Tue, Jun 18, 2019 at 11:30 PM Steven Schveighoffer via
Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>
> On 6/17/19 7:46 PM, Manu wrote:
> > Is this valid?
> >
> > int x;
> > void fun(scope ref shared(int) x) { ... }
> > fun(x); // implicit promotion to shared in this case
> >
> > This appears to promote a thread-local to shared. The problem with
> > such promotion is that it's not valid that a thread-local AND a shared
> > reference to the same thing can exist at the same time.
> >
> > With scope, we can guarantee that the reference doesn't escape the callee.
> > Since the argument is local to the calling thread, and since the
> > calling thread can not be running other code at the same time as the
> > call is executing, there is no way for any code to execute with a
> > thread-local assumption while the callee makes shared assumptions.
> >
> > I think this might be safe?
> >
>
> Seems like it would be safe, but what is the use case for it? If you
> have a scope shared, which can't actually get shared with anything else,
> what does it buy you?

parallel foreach.


More information about the Digitalmars-d mailing list