atomic.Load() 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 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 method has been done for this 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 (v *Value) Load() (x interface{}) Here, v is the value of any type and x is the interface which is the output result type of Load as well as Store method. Note: (*Value) is the pointer to a Value type. And Value type supplied in the sync/atomic standard package is used to atomically load as well as store values of any type. Return Value: It returns the value set stored by the store method. And can also return nil if store method is not called. Example 1: C // Program to illustrate the usage of // Load function in Golang // Including main package package main // importing fmt and sync/atomic import ( "fmt" "sync/atomic" ) // Main function func main() { // Defining a struct type L type L struct{ x, y, z int } // Defining a variable to assign // values to the struct type L var r1 = L{9, 10, 11} // Defining Value type to store // values of any type var V atomic.Value // Calling Store function V.Store(r1) // Calling Load method var r2 = V.Load().(L) // Prints values as // stored by recent // store method fmt.Println(r2) // Displays true if satisfied fmt.Println(r1 == r2) } Output: {9 10 11} true In the above example, we have used Value type in order to store the values of any type. And these values are stored at r1 which is the interface stated. However, these values can be returned using the Load method. Example 2: C // Program to illustrate the usage of // Load function in Golang // Including main package package main // importing fmt and sync/atomic import ( "fmt" "sync/atomic" ) // Main function func main() { // Defining a struct type L type L struct{ x, y, z int } // Defining a variable to assign // values to the struct type L var r1 = L{9, 10, 11} // Defining Value type to store // values of any type var V atomic.Value // Calling Load method var r2 = V.Load().(L) // Prints values as // stored by recent // store method fmt.Println(r2) // Displays true if satisfied fmt.Println(r1 == r2) } Output: panic: interface conversion: interface {} is nil, not main.L goroutine 1 [running]: main.main() /tmp/sandbox731326366/prog.go:28 +0x240 Here, no call to store method has been done so nil is returned. Comment More infoAdvertise with us Next Article atomic.Load() 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.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.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.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.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.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.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.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.StoreInt32() Function in Golang With Examples In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The StoreInt32() 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 Like