[dmd-concurrency] Smoke test

Walter Bright walter at digitalmars.com
Fri Jan 8 02:18:16 PST 2010



Sean Kelly wrote:
> On Jan 8, 2010, at 12:36 AM, Walter Bright wrote:
>   
>> Sean Kelly wrote:
>>     
>>> I feel like I'm not explaining myself very well, but that's the best I can do at the moment.  As a related issue, I have a feeling that the following is a bad idea, but I haven't come up with a good explanation for why yet, maybe simply the principle of least surprise?:
>>>
>>> class C
>>> {
>>>    shared int x;
>>> }
>>>
>>> auto c = new C;
>>> sendRefToAnotherThread( c ); // fails, c is local
>>> sendToAnotherThread( &c.x ); // succeeds, c.x is shared
>>>
>>>  
>>>       
>> The transitivity of shared doesn't work backwards, only forwards. In other words, you can have a local pointer to shared, but no shared pointers to locals.
>>
>> In yet other words, sharing is transitive, locality is not.
>>     
>
> So where would the compiler error on the example above?
>   

Assuming the prototypes are:

    void sendRefToAnotherThread(shared Object o);   // fail, c is not shared
    void sendToAnotherThread(shared void* p) ; // success, &c.x points 
to shared


More information about the dmd-concurrency mailing list