Atomic

Learn about the atomic in sync package.

We'll cover the following

The Atomic package

The atomic package provides low-level atomic operations on the memory, which are very useful for implementing synchronization algorithms. Before execution on hardware, the compiler converts the code into low-level atomic statements. But merging several atomic statements doesn’t lead to an atomic block-of-code, and the atomic operation is lockless.

Let’s take a straightforward example to understand the atomic operation. First, let’s see the unsynchronized code. We can use a mutex to solve this as well.

Get hands-on with 1200+ tech skills courses.