top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Is a + b atomic operation ??

+3 votes
398 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
...