Struggling to implement parallel foreach...

Kagamin spam at here.lot
Sun Jun 16 07:55:11 UTC 2019


On Saturday, 15 June 2019 at 06:13:09 UTC, Manu wrote:
> struct S
> {
>   void method() shared;
> }
>
> void test()
> {
>   S s;
>   void localFun() shared
>   {
>     s.method(); // <- s must transitively receive const from the
> context pointer, otherwise this doesn't work
>   }
> }
>
> Current semantics would reject this, because s is not shared, 
> and
> therefore not accessible by localFun.
> The unnecessary complexity inhibits the only useful thing that a
> shared function can do.

Declare `s` as shared and it will work. It would receive 
qualifier from context, but unshared variables can't be captured 
by shared closure to begin with because unshared data can't part 
of shared context, because that would break the guarantee that 
unshared data shouldn't be shared. Currently compiler implements 
check which variables can be captured and which can't.


More information about the Digitalmars-d mailing list