File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which of the following is an atomic operation?

 
azuki ooh
Greenhorn
Posts: 20
  • 0
  • 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: 20832
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic