ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Golang program to demonstrate the atomic.LoadInt32() function

Here, we are going to demonstrate the atomic.LoadInt32() function in Golang (Go Language).
Submitted by Nidhi, on May 04, 2021

Problem Solution:

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.

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.

// 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.

Golang sync/atomic Package Programs »



ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.