[dmd-concurrency] synchronized, shared, and regular methods inside the same class

Michel Fortin michel.fortin at michelf.com
Mon Jan 4 17:34:46 PST 2010


Le 2010-01-04 à 18:58, Andrei Alexandrescu a écrit :

> int y = sharedRead(x);
> ++y;
> sharedWrite(y, x);
> 
> When writing such code the user inevitably hits on the documentation for the two intrinsics, which clearly define their guarantees: only the sequence of sharedRead and sharedWrite is preserved. At that point, inspecting the code and understanding how it works is improved.

I think it could be better than that. Having a lot of functions with various names makes the code much less readable since the logic needs to be expressed in a completely different syntax.

What I'd like is if regular operators could work as atomic operations. It'd be great if ++atomic(y) could translate to atomic increment, atomic(y) = 10 could be used insert a write barrier, and x = atomic(y) could translate to something that reads y with a read barrier. You could even have atomic(y) += 3 for an atomic add. I believe most of this can be achieved with a struct and proper operator overloading.

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





More information about the dmd-concurrency mailing list