Home : Software Terms : Race Condition Definition

Race Condition

A race condition occurs when a software program depends on the timing of one or more processes to function correctly. If a thread runs or finishes at an unexpected time, it may cause unpredictable behavior, such as incorrect output or a program deadlock.

Most software programs are multithreaded, meaning they can process several threads at once. A well-programmed application will ensure the results of each thread are processed in the expected order. If a program relies on threads that run in an unpredictable sequence, a race condition may occur.

A simple example is a logic gate that handles boolean values. The AND logic gate has two inputs and one output. If inputs A and B are true, the AND gate produces TRUE. If one or both inputs are false, it produces FALSE. A race condition may happen if a program checks the logic gate result before variables A and B are loaded. The correct process would be:

  1. Load variable A
  2. Load variable B
  3. Check result of the AND logic gate

An incorrect sequence would be:

  1. Load variable A
  2. Check result of the AND logic gate
  3. Load variable B

The result of the second example above may or may not be the same as the first example. For instance, variable B may be FALSE before and after it is loaded, which would not change the result. If A is FALSE, it does not matter whether or not B is TRUE or FALSE. However, if both A and B are true, the result should be TRUE. Loading variable B after checking the result of the logic gate would produce an incorrect result of FALSE.

The inconsistent output produced by race conditions may cause bugs that are difficult to detect. Programmers can avoid these issues by ensuring threads are processed in a consistent sequence.

Updated: January 24, 2020

Cite this definition:

https://techterms.com/definition/race_condition

TechTerms - The Tech Terms Computer Dictionary

This page contains a technical definition of Race Condition. It explains in computing terminology what Race Condition means and is one of many software terms in the TechTerms dictionary.

All definitions on the TechTerms website are written to be technically accurate but also easy to understand. If you find this Race Condition definition to be helpful, you can reference it using the citation links above. If you think a term should be updated or added to the TechTerms dictionary, please email TechTerms!

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe at any time.
Questions? Please contact us.