This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons 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: 18546
    
  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?
 
Similar Threads
Another thread question
Can not decide in this scenario:
Enthuware toughest question doubt
Tricky assignment i=i++;
Just Basic