On Mon, 04 Jun 2012 07:17:45 -0400, Michel Fortin
<michel.for...@michelf.com> wrote:
After trying to make sense of the thread "synchronized
(this[.classinfo]) in druntime and phobos", I had to write my opinion on
all this somewhere that wouldn't be instantly lost in a bazilion of
posts. It turned out into something quite elaborate.
<http://michelf.com/weblog/2012/mutex-synchonization-in-d/>
I like this. But it needs a lot of work.
A few comments:
1. This does not handle shared *at all*. Presumably, there is no reason
to lock unshared data, so this has to be handled somewhere. If you say
"synchronized implies shared", well, then how do you have a shared int
inside an unshared class? My instinct is that all the methods that need
to used synchronized need to be declared shared (meaning the whole class
data is shared). But that sucks, because what if you have a thread-local
instance?
I have an idea to solve this. Since the mutexes are implicit, we can
declare space for them, but only allocate them when the class instance is
shared (allocated on construction). Then when synchronized goes to lock
them, if they are null, do nothing.
But what if some data is not marked synchronized?
I can see why Bartosz had such trouble creating a sharing system in a
simple manner...
2. As far as determining a mutex to protect multiple items of data, what
about:
synchronized(symbolname) int x, int y;
or
synchronized(symbolname)
{
int x;
int y;
}
where you cannot do synchronized(x) or synchronized(y), and cannot read or
write x or y without doing synchronized(symbolname).
-Steve