Race condition

Updated: 11/13/2018 by Computer Hope

A race condition or race hazard is a scenario in electronic processing where the calculation result might be affected by an unforeseen or uncontrolled sequence of events. The underlying concept is that the results of a process should never be affected by one of the operations "winning a race" (finishing first).

Race condition example

Consider the following set of operations:

  1. variable a = 1
  2. variable a = a * 5
  3. variable b = a - 1

If these operations are processed in the proper sequence, variable b should equal 4. But if operation 3 is executed before operation 2 has completed, b would equal 0.

Race conditions in processors

Race conditions are an important problem in CPU (central processing unit) design that use both parallel and concurrent processing techniques to execute multiple instructions in an overlapping time frame. To ensure that the output of calculations is not corrupted, race conditions must always be anticipated and avoided.

Race conditions in software

It's also an important problem for software developers, who must handle any race conditions that may occur when their code is used in real-world situations. Famously, an improperly handled race condition in the software of NASA's Spirit exploration rover nearly resulted in the rover being lost shortly after it landed on Mars.

Design, Parallel processing, Programming terms