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

Kevin Bealer kevinbealer at gmail.com
Tue Jan 5 10:14:32 PST 2010


On Mon, Jan 4, 2010 at 6:58 PM, Andrei Alexandrescu <andrei at erdani.com>wrote:

>
> shared int x;
> ...
> ++x;
>
> The putative user notices that that doesn't work, so she's like, meh, I'll
> do this then:
>
> int y = x;
> ++y;
> x = y;
>
> And the user remains with this impression that the D compiler is a bit
> dumb. Of course that doesn't avoid the race condition though. If the user
> would have to call atomicIncrement(x) that would be clearly an improvement,
> but even this would be an improvement:
>
> 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.
>
> ...
>
 Andrei
>

Just to clarify, this is still broken, right?  I mean that if two users are
calling a method that does this,
the value of x will only get incremented once if their calls to
sharedRead/sharedWrite are interleaved?

Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dmd-concurrency/attachments/20100105/066a6637/attachment.htm>


More information about the dmd-concurrency mailing list