Here, we will loaded the value of 32-bit integer variable using atomic.LoadInt32() function. In the atomic.LoadInt32() function, we passed address of variables. The atomic.LoadInt32() function is used the values of variables in multithreaded/multi-process environment.
The source code to demonstrate the atomic.LoadInt32() function is given below. The given program is compiled and executed on the ubuntu 18.04 operating system successfully.
// Golang program to demonstrate the
// atomic.LoadInt32() function
package main
import "fmt"
import "sync/atomic"
//Entry point for the program
func main() {
var num1 int32 = 786
var num2 int32 = 111
loadVal1 := atomic.LoadInt32(&num1)
loadVal2 := atomic.LoadInt32(&num2)
//Print 32-bit integer loaded value
fmt.Println(loadVal1)
fmt.Println(loadVal2)
}
Output:
786
111
Explanation:
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the required packages to predefined functions.
In the main() function, we created two 32-bit integer variables num1, num2 that are initialized with 786, 111 respectively. Then we loaded the value of 32-bit integers using the atomic.LoadInt32() function. The atomic.LoadInt32() function is used the values of variables in multithreaded/multi-process environment. At last, we printed the loaded value of variables on the console screen.
Program/Source Code:
The source code to demonstrate the atomic.LoadInt32() function is given below. The given program is compiled and executed on the ubuntu 18.04 operating system successfully.
Output:
Explanation:
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the required packages to predefined functions.
In the main() function, we created two 32-bit integer variables num1, num2 that are initialized with 786, 111 respectively. Then we loaded the value of 32-bit integers using the atomic.LoadInt32() function. The atomic.LoadInt32() function is used the values of variables in multithreaded/multi-process environment. At last, we printed the loaded value of variables on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer