In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The SwapUint64() function in Go language is used to atomically store new value into *addr and returns the previous *addr value. This function is defined under the atomic package. Here, you need to import “sync/atomic” package in order to use these functions.
func SwapUint64(addr *uint64, new uint64) (old uint64)
Here, addr indicates address. And new is the new uint64 value and old is the older uint64 value.
Note: (*uint64) is the pointer to a uint64 value. And uint64 is an integer type of bit size 64. However, uint64 contains the set of all unsigned 64-bit integers from 0 to 18446744073709551615.
Return value: It stores the new uint64 value into the *addr and returns the previous *addr value.
Stored new value: 65353443, Old value: 10864545453
Here, the oldVal1 is equal to “m” as the new value to be stored in the *addr is same as an old value so, true is returned but oldVal2 is not equal to “n” as there the old value is not similar to the newly assigned value hence, false is returned.