Golang program to demonstrate the atomic.LoadInt64() function

Here, we are going to demonstrate the atomic.LoadInt64() function in Golang (Go Language).
Submitted by Nidhi, on May 04, 2021 [Last updated : March 05, 2023]

atomic.LoadInt64() function in Golang

Problem Solution:

Here, we will loaded the value of 64-bit integer variable using atomic.LoadInt64() function. In the atomic.LoadInt64() function, we passed address of variables. The atomic.LoadInt64() function is used the values of variables in multithreaded/multi-process environment.

Program/Source Code:

The source code to demonstrate the atomic.LoadInt64() function is given below. The given program is compiled and executed on the ubuntu 18.04 operating system successfully.

Golang code to demonstrate the example of atomic.LoadInt64() function

// Golang program to demonstrate the
// atomic.LoadInt64() function

package main

import "fmt"
import "sync/atomic"

// Entry point for the program
func main() {
	var num1 int64 = 78612344444
	var num2 int64 = 11187432762

	loadVal1 := atomic.LoadInt64(&num1)
	loadVal2 := atomic.LoadInt64(&num2)

	//Print 64-bit integer loaded value
	fmt.Println(loadVal1)
	fmt.Println(loadVal2)
}

Output:

78612344444
11187432762

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 64-bit integer variables num1, num2 that are initialized with 78612344444, 11187432762 respectively. Then we loaded the value of 64-bit integers using the atomic.LoadInt64() function. The atomic.LoadInt64() 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.

Golang sync/atomic Package Programs »





All Golang Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.