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

Sean Kelly sean at invisibleduck.org
Tue Nov 2 07:20:44 PDT 2010


On Nov 1, 2010, at 10:49 AM, David Simcha wrote:

> 
> 
> On Mon, Nov 1, 2010 at 1:39 PM, Michel Fortin <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.

The second form is only atomic when preceded by a LOCK modifier.  It's still done in the CPU as a RMW operation.



More information about the phobos mailing list