On Friday, 11 October 2013 at 01:05:19 UTC, Jonathan M Davis wrote:
On Friday, October 11, 2013 02:08:16 Sean Kelly wrote:

Shared data needs to be
treated differently, explicitly, or things go downhill fast.

I'm not disagreeing with how shared works. I'm disagreeing with the idea that it's not supposed to be normal to cast shared away when operating on shared objects. I expect that the most common idiom for dealing with shared is to protect it with a lock, cast it to thread-local, do whatever you're going to do with it, make sure that there are no thread-local references to it once
you're done operating on it, and then release the lock.

The thing with locks is that you need to use the same lock for all accesses to a set of mutated data or atomicity isn't guaranteed. And if you're locking externally you don't know what might change inside a class during a method call, so you have to use the same lock for all operations on that object, regardless of what you're doing. At that point you may as well just synchronize on the class itself and be done with it. So sure, it saves you from having to define shared or synchronized methods, but I don't think this should be how we want to write concurrent code in D.

Reply via email to