[dmd-concurrency] tail-shared by default?

Sean Kelly sean at invisibleduck.org
Sat Jan 9 10:35:35 PST 2010


On Jan 9, 2010, at 10:28 AM, Michel Fortin wrote:

> Le 2010-01-09 à 13:00, Sean Kelly a écrit :
> 
>> I think this will all actually work out if the compiler detects when a shared value doesn't escape its local scope and thus doesn't need synchronization. If I have a private shared class member of a local class instance then the compiler should reliably be able to determine that the reference itself isn't visible yo another thread and therfore doesn't need to be atomic.  
>> Calls to the shared class instance will still need to be restricted to shared and synchronized members, but the call won't need to be atomic(a).foo().
> 
> I disagree. If you have a private class member which is shared it might be because the class itself will give its address to another thread.
> 
> Take this example:
> 
> 	class ObjectGenerator {
> 		private shared Object latestObject_;
> 
> 		this() {
> 			startThreadToUpdateObjectAtRegularIntervals(&latestObject_);
> 		}
> 
> 		shared Object latestObject() @property {
> 			return sharedRead(latestObject_);
> 		}
> 	}

How often have you passed the address of a reference anywhere?  I can't think of a single time I've done this.  In the spare few instances where this happens, it seems totally reasonable that use of the reference should be atomic.


More information about the dmd-concurrency mailing list