File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Which of the following is an atomic operation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Which of the following is an atomic operation?" Watch "Which of the following is an atomic operation?" New topic
Author

Which of the following is an atomic operation?

azuki ooh
Greenhorn

Joined: Nov 07, 2008
Posts: 20
(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
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
azuki ooh
Greenhorn

Joined: Nov 07, 2008
Posts: 20
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which of the following is an atomic operation?