This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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 Head First Android this week in the Android 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: 19932
    
  43

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!
 
 
subject: Which of the following is an atomic operation?
 
It's not a secret anymore!