[dmd-concurrency] A synchronized storage class?
Michel Fortin
michel.fortin at michelf.com
Thu Jan 7 04:39:20 PST 2010
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
}
}
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the dmd-concurrency
mailing list