atomic.LoadPointer() Function in Golang With Examples Last Updated : 28 Apr, 2025 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 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 "unsafe" package in order to use these functions.Syntax: func LoadPointer(addr *unsafe.Pointer) (val unsafe.Pointer) Here, addr indicates address.Note: (*unsafe.Pointer) is the pointer to a unsafe.Pointer value. And unsafe.Pointer type is helpful in enabling transitions between arbitrary types and builtin uintptr type. Moreover, unsafe is a package that is helpful in type safety of Go programs.Return Value: It automatically loads *addr and returns unsafe.Pointer.Example 1: C // Program to illustrate the usage of // LoadPointer function in Golang // Including main package package main // importing fmt, // sync/atomic and unsafe import ( "fmt" "sync/atomic" "unsafe" ) // Defining a struct type L type L struct{ x, y, z int } // Declaring pointer // to L struct type var PL *L // Calling main func main() { // Defining *addr unsafe.Pointer var unsafepL = (*unsafe.Pointer)(unsafe.Pointer(&PL)) // Defining value // of unsafe.Pointer var px L // Calling StorePointer and // storing unsafe.Pointer // value to *addr atomic.StorePointer( unsafepL, unsafe.Pointer(&px)) // Calling LoadPointer() method px1 := (*L)(atomic.LoadPointer(unsafepL)) // Returns true if *addr is // loaded else returns false fmt.Println(px1 == &px) // Prints unsafe.Pointer fmt.Println(&px1) } Output: true 0xc0000b8018 // Can be different at different run times Here, the StorePointer method adds value to the *addr and then LoadPointer method atomically loads *addr. So, here loading is accomplished hence, true is returned and the value of unsafe.Pointer returned here can be different at different run times.Example 2: C // Program to illustrate the usage of // LoadPointer function in Golang // Including main package package main // importing fmt, // sync/atomic and unsafe import ( "fmt" "sync/atomic" "unsafe" ) // Defining a struct type L type L struct{ x, y, z int } // Declaring pointer // to L struct type var PL *L // Calling main func main() { // Defining *addr unsafe.Pointer var unsafepL = (*unsafe.Pointer)(unsafe.Pointer(&PL)) // Defining value // of unsafe.Pointer var px L // Calling LoadPointer() method px1 := (*L)(atomic.LoadPointer(unsafepL)) // Returns true if *addr is // loaded else returns false fmt.Println(px1 == &px) // Prints unsafe.Pointer fmt.Println(&px1) } Output: false 0xc00000e028 // A random value is returned in each run Here, false is returned as here the unsafe.pointer is not stored before so, LoadPointer() method was not able to load the *addr. Moreover, the address value returned here is the address of px1. Comment More infoAdvertise with us Next Article atomic.LoadPointer() Function in Golang With Examples nidhi1352singh Follow Improve Article Tags : Go Language GoLang-atomic Similar Reads atomic.LoadInt32() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The LoadInt32() 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.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.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.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.Load() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The Load() function in Go language is used to check the value set of the most current values as stored by Store method. Moreover, it can also return nil if no calls to Store m 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 atomic.StorePointer() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The StorePointer() 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 the "sync/at 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.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 Like