atomic.SwapUintptr() 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 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 package. Here, you need to import "sync/atomic" package in order to use these functions. Syntax: func SwapUintptr(addr *uintptr, new uintptr) (old uintptr) Here, addr indicates address. And new is the new uintptr value and old is the older uintptr value. Note: (*uintptr) is the pointer to a uintptr value. And uintptr is an integer type that is too large that it can contain the bit pattern of any pointer. Return Value: It stores the new uintptr value into the *addr and returns the previous *addr value. Example 1: C // Program to illustrate the usage of // SwapUintptr function in Golang // Including main package package main // Importing fmt and sync/atomic import ( "fmt" "sync/atomic" ) // Main function func main() { // Assigning value to uintptr var x uintptr = 96464646466757 // Using SwapUintptr method // with its parameters var old_val = atomic.SwapUintptr(&x, 21863567864) // Prints new and old value fmt.Println("Stored new value: ", x, ", Old value: ", old_val) } Output: Stored new value: 21863567864, Old value: 96464646466757 Example 2: C // Program to illustrate the usage of // SwapUintptr function in Golang // Including main package package main // Importing fmt and sync/atomic import ( "fmt" "sync/atomic" ) // Main function func main() { // Assigning value to uintptr var m uintptr = 4235564747474 var n uintptr = 2567891937466 // Using SwapUintptr method with its parameters var oldVal1 = atomic.SwapUintptr(&m, 4235564747474) var oldVal2 = atomic.SwapUintptr(&n, 7454545419024) // 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 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.SwapUintptr() Function in Golang With Examples nidhi1352singh Follow Improve Article Tags : Go Language GoLang-atomic Similar Reads 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.SwapUint64() Function in Golang With Examples 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 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.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.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.LoadUintptr() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The LoadUintptr() 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 i 2 min read atomic.StoreUintptr() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The StoreUintptr() 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.Store() Function in Golang With Examples In Go language, atomic packages supply lower level atomic memory that is helpful is implementing synchronization algorithms. The Store() function in Go language is used to set the value of the Value to x(i.e, interface). And all the calls to Store method for a stated Value should use values of an id 3 min read atomic.LoadPointer() Function in Golang With Examples In Go language, atomic packages supply lower level atomic memory that is helpful is implementing synchronization algorithms. The LoadPointer() 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" and "unsa 3 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