Sharing in D

Steven Schveighoffer schveiguy at yahoo.com
Fri Aug 8 07:24:59 PDT 2008


"Russell Lewis" wrote
> Steven Schveighoffer wrote:
>> "Russell Lewis" wrote
>>> Walter Bright wrote:
>>>> Shared cannot be implicitly cast to unshared. Just like const cannot be 
>>>> implicitly cast to mutable.
>>> But you can implicitly cast unshared to shared, right?
>>
>> No.  There is no implicit casting or else you can have data that is 
>> shared and unshared at the same time.  It will be up to the coder to 
>> ensure only one is happening at a time.
>
> Yeah, I saw your (was it you?) example of how that would become 
> problematic.  Did you see my "scope locks" idea as a possible way to 
> safely move data between the shared & unshared realms?

I think there may be no middle ground, as in order for locks to work, every 
access to a locked variable must be through the lock.  If you have 2 
references to a variable, one that is shared and one that is not, locking on 
the shared variable does nothing to prevent the unshared variable from being 
accessed without the lock.

I think the middle ground simply needs to do the most safe thing (i.e. treat 
as shared), but not allow implicit casting to unshared or shared.

However, in this case, you incur a possible performance hit when it might 
not be necessary.  It might be that the middle ground is simply undesirable, 
so you have to do explicit casting.

I'm not sure.

-Steve 





More information about the Digitalmars-d mailing list