user3528733
user3528733

Reputation: 1299

Atomic operation in multi threaded workld

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).

Upvotes: 0

Views: 81

Answers (1)

rkosegi
rkosegi

Reputation: 14638

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.

Upvotes: 4

Related Questions