# Detecting Race Conditions With Go

DevFeed: [Detecting Race Conditions With Go](<https://devfeed.tech/articles/detecting-race-conditions-with-go-22070.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2013/09/detecting-race-conditions-with-go.html>)

Published: 2013-09-26T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [race-condition](<https://devfeed.tech/topics/race-condition.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>), [Tooling](<https://devfeed.tech/topics/tooling.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [code](<https://devfeed.tech/tags/code.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [logging](<https://devfeed.tech/tags/logging.md>), [programming](<https://devfeed.tech/tags/programming.md>), [race-condition](<https://devfeed.tech/tags/race-condition.md>), [tooling](<https://devfeed.tech/tags/tooling.md>)

## AI overview

This tutorial explains race conditions in Go and demonstrates how Go's race detector can identify unsynchronized access to shared resources. It uses a concurrent program that increments a shared counter and shows how to build and run it with the -race option.

## Source excerpt

I always find it interesting when I realize that something I have been practicing or dealing with for a long time has a name. This time it happens to be race conditions. This is something you can't avoid thinking about as soon as you have more than one routine sharing any kind of resource. If you're not thinking about race conditions in your code, now is the time. A race condition is when two or more routines have access to the same resource, such as a variable or data structure and attempt to read and write to that resource without any regard to the other routines. This type of code can create the craziest and most random bugs you have ever seen. It usually takes a tremendous amount of logging and luck to find these types of bugs. Over the years I have really perfected my logging skills to help identify these problems when they occur. Back in June with Go version 1.1, the Go tooling introduced a race detector. The race detector is code that is built into your program during the build process. Then once your program is running, it is able to detect and report any race conditions it finds. It is seriously cool and does an incredible job in identifying the code that is the culprit. Let's take a very simple program that contains a race condition and build the code with the race detector.