Sharing in D

Walter Bright newshound1 at digitalmars.com
Fri Aug 1 10:35:04 PDT 2008


superdan wrote:
> Walter Bright Wrote:
> 
>> Sean Kelly wrote:
>>> == Quote from Walter Bright (newshound1 at digitalmars.com)'s
>>> article
>>>> If conventional code were generated for i++, and i was accessed
>>>> from multiple threads, the code is *broken*.
>>> Not necessarily.  If i is a 32-bit number and only one thread is 
>>> doing the writing then the code could be perfectly safe.
>> If you've got only one thread, why is it shared ? If it is shared,
>>  there's the possibility of multiple threads, and so the code is
>> wrong wrong wrong.
> 
> i think he means a different case. you have many threads alright. but
> only one is incrementin'. others are just readin'.

If Sean means that the code is synchronized so only one thread has 
access, he is correct. In the proposed threading model, within a 
synchronized function, the shared object data can be accessed without 
fences and the ++ will work.

Essentially, within a synchronized function, the 'this' object becomes 
tail-shared. I know, AAAIIIEEEEE!



More information about the Digitalmars-d mailing list