[dmd-concurrency] shared arrays, real, shared classes, synchronized classes

Michel Fortin michel.fortin at michelf.com
Fri Jan 29 17:34:44 PST 2010


Le 2010-01-29 à 18:03, Andrei Alexandrescu a écrit :

> 1. Atomic array assignment is in.
> 
> We discussed that and concluded the following:
> 
> * CMPXCHG16B and friends are the norm of modern Intel-like machines, and are unlikely to go away soon. We are designing D for the future and the future looks like two-word assignment is in it.
> 
> * Pre-2004 AMDs and probably some other chips still lack two-word assignment. We decided that we will look for creative solutions to those problems as they come up (hat tip to Kevin's idea of using a spin lock).

Seems like a good decision.


> 2. Atomic assignment of real is still undecided.
> 
> I think I'll write in TDPL that it's platform dependent. Assignment to 80-bit reals on 32-bit machines is still problematic.

Not sure, but it could be architecture-dependent. I mean, the size of real is already architecture-dependent.


> 3. There are _no_ more synchronized or shared methods. That is, code like this is incorrect:
> 
> class A { void fun() shared { } }
> class B { void fun() synchronized { } }
> 
> Rationale: it is tenuous to offer mixed modes in the same class.


Good idea simplification.


> 4. The "synchronized" attribute is hoisted at class level:
> 
> synchronized class A { ... }
> 
> That means each and every method of that class is synchronized.
> 
> 5. The "shared" attribute is hoisted at class or struct level:
> 
> shared class A { ... }
> shared struct B { ... }
> 
> That means the implementation is lock-free and uses its own synchronization mechanisms.


I like it.

What happens with inheritance? Also, what happens if you have a shared variable in your synchronized class?


> 6. When defining an object of a synchronized of shared type, you still need to qualify it with "shared" in order to make it so. For example:
> 
> synchronized class A { ... }
> shared A a; // fine
> A b;        // error
> 
> (I'm not 100% sure about this.)

I agree with Robert Jacques, this won't work very well. Also, I think the third line above should declare a thread-local reference to a shared object. This would solve the tail-shared problem.


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the dmd-concurrency mailing list