#Atomic
1 articles
Knowing and Implementing Atomic Sync in Golang
Introduction to sync.Atomic
For atomic operations on variables in golang, the sync/atomic package offers certain low-level methods. In Go, these methods allow multiple goroutines to safely modify shared variables without using locks or other explicit synchronization. Functions like AddInt64
, AddUint32
, CompareAndSwapInt32
, etc. used to perform basic arithmetic on different types of variables can be found in the atom
package. The AddInt64
method for example, guarantees that modifications made by other goroutines will be seen when adding a certain value to an int64
variable in atomic style.