Two or more processes executing in a system with an illusion of concurrency and accessing shared data may try to change the shared data at the same time. This condition in the system is known as a race condition. To see the sample code for Race Condition in Golang, you can refer to this article.
Atomic package in Golang provides the low-level locking mechanisms for synchronizing access to pointers and integers etc. The atomic/sync package functions are used to fix the race condition.
Here, you can see we are using atomic.AddInt32() function to synchronize the addition of the integer values so that only one goroutine is allowed to complete the add operation at a time. Remember one thing, always check the output of such a program using the online compiler as you might get the same output every time(means no race condition) due to the deterministic nature. So use the local compiler like Visual Studio or CMD to see the results.
- Atomic Variable in Golang
- How to Fix a 401 Unauthorized Error?
- How to fix the height of rows in the table?
- Inverse functions and composition of functions
- Fruitful Functions and Void Functions in Julia
- How to use Array Reverse Sort Functions for Integer and Strings in Golang?
- How to write :hover condition for a:before and a:after in CSS?
- if/else condition in CSS
- How to append class if condition is true in Haml?
- How to bind an array to an IN() condition in PHP ?
- Condition Handling in R Programming
- How to Display/Hide functions using aria-hidden attribute in jQuery ?
- How to Create Custom Errors using New Function in Golang?
- How to iterate over an Array using for loop in Golang?
- How to create a Struct Instance Using a Struct Literal in Golang?
- How to Calculate the Average using Arrays in Golang?
- How to instantiate Struct using new keyword in Golang?
- Golang Program that Removes Duplicates Using Nested Loops
- How to Copy Struct Type Using Value and Pointer Reference in Golang?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.