[dmd-concurrency] A synchronized storage class?

Sean Kelly sean at invisibleduck.org
Thu Jan 7 06:49:39 PST 2010


Is "synchronized" really neded here?  I was hoping those variables  
could remain impaneled, so synchronized functions would simply be the  
way to operate on normal variables in a shared object.

Sent from my iPhone

On Jan 7, 2010, at 4:39 AM, Michel Fortin <michel.fortin at michelf.com>  
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
>        }
>    }
>
>
> -- 
> Michel Fortin
> michel.fortin at michelf.com
> http://michelf.com/
>
> _______________________________________________
> dmd-concurrency mailing list
> dmd-concurrency at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-concurrency


More information about the dmd-concurrency mailing list