[dmd-concurrency] tail-shared by default?

Walter Bright walter at digitalmars.com
Fri Jan 8 21:00:47 PST 2010



Steve Schveighoffer wrote:
> ----- Original Message ----
>
>   
>> From: Walter Bright <walter at digitalmars.com>
>>
>> All that's necessary is to take the address of a shared local and pass it to 
>> another thread:
>>
>>   void foo()
>>   { shared int x;
>>      passToAnotherThread(&x);
>>      x++;     // <=== synchronization issues!
>>      waitForThreadToFinish();
>>    }
>>
>>     
>
> In my scheme the declaration of x above is illegal.  You cannot share stack data.
>
> Even if you have:
>
> void foo()
> {
>    shared int * x; // ok, equivalent to shared(int)*
>    passToAnotherThread(&x); // error, &x is shared(int)**, cannot convert to shared (int *)*
> }
>
> basically, it's impossible to have a fully shared local variable, all shared local variables are tail-shared.  The only place fully shared data can be is global data or the heap.  This is in essence exactly how it should be -- you are not sharing the pointer that you copy onto the stack, you are sharing what it points to.
>
> -Steve
>
>   

Tail-shared doesn't work as soon as classes come into the picture (or 
any reference types).


More information about the dmd-concurrency mailing list