Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which of the following is an atomic operation?

 
azuki ooh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(a) temp = temp + 1;
(b) X = temp;
(c) int temp = X;

I read somewhere that assignment operation are atomic. Incremental operation is not. So I conclude that (c) is atomic. Am I right?
 
Henry Wong
author
Marshal
Pie
Posts: 21123
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
azuki ooh wrote:(a) temp = temp + 1;
(b) X = temp;
(c) int temp = X;

I read somewhere that assignment operation are atomic. Incremental operation is not. So I conclude that (c) is atomic. Am I right?


Yes, C is definitely atomic. B may also be atomic, depending on the data type and the JVM. Also, there are other issues, such as register caching. Atomic doesn't mean thread safe.

Henry
 
azuki ooh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic