On Fri, Jul 26, 2013 at 11:57 AM, Sze Howe Koh <[email protected]>wrote:
> On 26 July 2013 12:57, Mandeep Sandhu <[email protected]> wrote: > > On Thu, Jul 25, 2013 at 9:04 PM, Thiago Macieira < > [email protected]> > >> int inc(int &foo) > >> { > >> return foo++; // not atomic anywhere > > > > > > Why? Because of the way foo is being received in this function, i.e by > > reference (so any operation on foo has and added level of indirection)? > > Because that's simply a shorthand for 3 separate operations. See > > http://stackoverflow.com/questions/10503737/is-increment-an-integer-atomic-in-x86 > Well, thats why I asked the previous question, i.e if foo is of machine word size or less, _then_ will the compiler generate the atomic fetch and add instruction or will that have to be done explicitly by the programmer? I understand that any (programming) language statement that results in multiple processor instructions will not be atomic (I'm not considering explicit lock being done in the program), since instruction from other processes/threads can be scheduled in-between. I guess I better write a small program and see for myself what are the instructions generated for it! :) -mandeep > > > Regards, > Sze-Howe >
_______________________________________________ Interest mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/interest
