atomic.SwapUint64() Function in Golang With Examples Last Updated : 01 Apr, 2020 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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. Example 1: C // Program to illustrate the usage of // SwapUint64 function in Golang // Including main package package main // Importing fmt and sync/atomic import ( "fmt" "sync/atomic" ) // Main function func main() { // Assigning value to uint64 var x uint64 = 10864545453 // Using SwapUint64 method // with its parameters var old_val = atomic.SwapUint64(&x, 65353443) // Prints new and old value fmt.Println("Stored new value: ", x, ", Old value: ", old_val) } Output: Stored new value: 65353443, Old value: 10864545453 Example 2: C // Program to illustrate the usage of // SwapUint64 function in Golang // Including main package package main // Importing fmt and sync/atomic import ( "fmt" "sync/atomic" ) // Main function func main() { // Assigning value to uint64 var m uint64 = 11735344343 var n uint64 = 976364747 // Using SwapUint64 method // with its parameters var oldVal1 = atomic.SwapUint64(&m, 11735344343) var oldVal2 = atomic.SwapUint64(&n, 6586850111) // Prints output fmt.Println((oldVal1) == m) fmt.Println((oldVal2) == n) } Output: true false 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. Comment More infoAdvertise with us Next Article atomic.SwapUint64() Function in Golang With Examples nidhi1352singh Follow Improve Article Tags : Go Language GoLang-atomic Similar Reads atomic.SwapInt64() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The SwapInt64() 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 packag 2 min read atomic.SwapUint32() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The SwapUint32() 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 packa 2 min read atomic.SwapInt32() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The SwapInt32() 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 packag 2 min read atomic.SwapUintptr() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The SwapUintptr() 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 pack 2 min read atomic.LoadUint64() Function in Golang With Examples In Go language, atomic packages supply lower level atomic memory that is helpful is implementing synchronization algorithms. The LoadUint64() function in Go language is used to atomically load *addr. This function is defined under the atomic package. Here, you need to import "sync/atomic" package in 2 min read atomic.StoreUint64() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The StoreUint64() function in Go language is used to atomically store val into *addr. This function is defined under the atomic package. Here, you need to import "sync/atomic" 2 min read atomic.LoadInt64() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The LoadInt64() function in Go language is used to atomically loads *addr. This function is defined under the atomic package. Here, you need to import "sync/atomic" package in 2 min read atomic.SwapPointer() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The SwapPointer() 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 pack 3 min read atomic.StoreInt64() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The StoreInt64() function in Go language is used to atomically store val into *addr. This function is defined under the atomic package. Here, you need to import "sync/atomic" 2 min read atomic.LoadUint32() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The LoadUint32() function in Go language is used to atomically load *addr. This function is defined under the atomic package. Here, you need to import "sync/atomic" package in 2 min read Like