[Interest] QMap and thread-safe.
Mandeep Sandhu
mandeepsandhu.chd at gmail.com
Fri Jul 26 08:39:43 CEST 2013
On Fri, Jul 26, 2013 at 11:57 AM, Sze Howe Koh <szehowe.koh at gmail.com>wrote:
> On 26 July 2013 12:57, Mandeep Sandhu <mandeepsandhu.chd at gmail.com> wrote:
> > On Thu, Jul 25, 2013 at 9:04 PM, Thiago Macieira <
> thiago.macieira at intel.com>
> >> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130726/6389fc45/attachment.html>
More information about the Interest
mailing list