Are atomic operations safe enough to use it in multi threaded app without causing race conditions and other concurrency issue ? Let say that we don't worry about visibility (we read/write everything from CPU).
Asked
Active
Viewed 72 times
0
-
Yes, Java provides a number of atomic types and operations. What is your exact question? – Tim Biegeleisen Oct 27 '17 at 07:06
-
First of all... what do you mean with "atomic operations"? Do you mean those, that are defined as atomically by the JLS or do you mean the Operations on e.g an [AtomicInteger](https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/atomic/AtomicInteger.html)? – Turing85 Oct 27 '17 at 07:07
-
Possible duplicate of [What does "atomic" mean in programming?](https://stackoverflow.com/questions/15054086/what-does-atomic-mean-in-programming) – Turing85 Oct 27 '17 at 07:14
-
By atomic operation I mean e.g i++ (where var 'i' is int), I am not talking about AtomicVariable. – user3528733 Oct 27 '17 at 11:01
1 Answers
4
Are atomic operations safe enough to use it in multi threaded app without causing race conditions and other concurrency issue?
Yes, java has strictly defined memory model (also known as JSR 133).
There are also out-of-box atomic wrappers for primitive types in java.util.concurrent package, like AtomicInteger.
Atomicity is implemented using compare-and-swap.

rkosegi
- 14,165
- 5
- 50
- 83
-
The question has nothing to do with Java in particular, but with the definition of atomicity. The memory model is irrelevant since OP explicitly said "we don't worry about visibility". – Turing85 Oct 27 '17 at 07:17
-
-
@Turing85 I think OP is related to java as question was tagged with java..isn't? – Neerav Vadodaria Oct 27 '17 at 09:28