[phobos] Fwd: Re: Ruling out arbitrary cost copy construction?

Andrei Alexandrescu andrei at erdani.com
Mon Nov 1 11:32:39 PDT 2010


Increment is not atomic on most processors, including x86 (inc 
[someAddress] does not exist).

Andrei

On 11/1/10 12:49 PM, David Simcha wrote:
>
>
> On Mon, Nov 1, 2010 at 1:39 PM, Michel Fortin <michel.fortin at michelf.com
> <mailto:michel.fortin at michelf.com>> wrote:
>
>
>     Is "i++" really atomic when i is a size_t? I though it was a
>     read-modify-write operation. The read might be atomic, the write
>     might be atomic, but the whole isn't. And in addition to atomicity,
>     it needs to be sequentially consistent unless we change the GC to
>     keep threads frozen while calling the destructors.
>
>
> In theory it could be read-modify-write because you never know if some
> incredibly stupid compiler will do something like:
>
> mov EAX, [someAddress];
> inc EAX;
> mov [someAddress], EAX;
>
> instead of just:
>
> inc [someAddress];
>
> However, I'm pretty sure the second form is atomic, and even if it's not
> formally guaranteed, any reasonable compiler would use the single inc
> instruction form.
>
>
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


More information about the phobos mailing list