How atomic package classes like AtomicInteger etc. work

I read that using atomic package classes allows us to make threads safe, block less coding. But I'm not very sure how the methods in the atomic package classes provide thread safety in the absence of locks or any keyword synchronization. Any help should be appreciated.

+4
source share
1 answer

They use very low level commands, such as Compare and Swap and several other methods from the sun.misc.Unsafe class.

Basically, calling a method such as compareAndSwap() will correspond to a unique processor instruction that fixes a lot of multithreading issues.

+12
source

Source: https://habr.com/ru/post/1432759/


All Articles