[dmd-concurrency] A synchronized storage class?

Andrei Alexandrescu andrei at erdani.com
Thu Jan 7 05:54:18 PST 2010


Adding a "synchronized" qualifier (with the semantics of tail-shared) 
has been discussed before. Our interim conclusion was that there is 
enough information inside synchronized methods to dispense with that 
particular qualifier.

We would very much like to _not_ add new qualifiers unless absolutely 
necessary. Your examples don't express that necessity - if you simply 
remove the "synchronized" qualifier off i and j, the compiler has enough 
information to do what's needed.


Andrei

Michel Fortin wrote:
> I'd like to propose "synchronized" as a storage class to help differentiate variables which are ok to use under a lock from variables intended for lock-free operations. The compiler can then enforce synchronized access to those variables:
> 
> 	class A {
> 		synchronized int i;
> 		synchronized int j;
> 		shared int k;
> 
> 		void test1() synchronized {
> 			++i; // ok: access to i is synchronized
> 			++j; // ok: access to j is synchronized
> 			++k; // error: k is shared, not synchronized; supports only atomic ops
> 			++atomic(k); // ok
> 		}
> 
> 		void test2() shared {
> 			++i; // error: access to i is synchronized, not shared
> 			++j; // error: access to j is synchronized, not shared
> 			++k; // error: shared only support atomic operations
> 			++atomic(k); // ok
> 		}
> 	}
> 
> 


More information about the dmd-concurrency mailing list