top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Is a + b atomic operation ??

+3 votes
72 views

It is possible to allocate CPU to thread2 in the mid of a + b? where a + b is in thread1.

posted Nov 6, 2013 by Vikas Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+3 votes

In C/C++ , It is not atomic operation. If you will check assembly program of this. It would be divided in getting value from registers, operation over those and storing back values. Even a++ is not atomic operation.

answer Nov 6, 2013 by Pankaj Agarwal
0 votes

Certain architectures support atomic addition or subtraction instructions, but there is no guarantee that the compiler would use them. If it is not performance-critical part of your code, you'd simply use a mutex.

answer Nov 6, 2013 by Majula Joshi
Similar Questions
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...