[dmd-concurrency] tail-shared by default?
Michel Fortin
michel.fortin at michelf.com
Sat Jan 9 10:28:37 PST 2010
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_);
}
}
Also note that it doesn't really work if sharedRead and sharedWrite are needed: the latestObject property returns a shared Object, but it should really be tail-shared, otherwise you'll need to use sharedRead to read the temporary value, which would be pretty messy. (Theoretically you'd need sharedWrite to write the temporary value in the return statement, but just can't imagine what it might be like.)
So either we have a TailShared!Object template, or we fix the problem at the language level.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the dmd-concurrency
mailing list