Concurrency - Race Condition (Concurrency Problem)

Data System Architecture

Concurrency - Race Condition (Concurrency Problem)

About

A Race condition is the only concurrent problem that can happen when two threads manipulate the same state (value) in the same time-lapse, the last thread to write the state will overwrite the state modification of the first thread.

same as Concurrency - Thread Interference (Interleave on shared data) ??

Race conditions have a reputation of being difficult to reproduce and debug, since the end result is non-deterministic and depends on the relative timing between interfering threads.

Problems occurring in production systems can therefore disappear when running in debug mode, when additional logging is added, or when attaching a debugger, often referred to as a wiki/Heisenbug. It is therefore better to avoid race conditions by careful software design rather than attempting to fix them afterwards.

If two threads run simultaneously without locking or synchronization, the outcome of the operation could be wrong.

Example

  • An object with a counter property with the state 1
  • The thread 1 enters an object and see the state 1
  • The thread 2 enters also the method and see the state 1
  • The thread 1 adds 1 to the counter, the state is 2
  • The thread 2 adds 1 to the counter, the state is 2 (whereas it should be 3)

Resolution

Data Problem

Raise conditions lead to data problem called phenomena.

Documentation / Reference





Discover More
Data System Architecture
Concurrency - Thread Interference (Interleave on shared data)

Same name than ? how errors are introduced when multiple threads access shared data. Interference happens when two operations, running in different threads, but acting on the same data, interleave....
Devtool Chrome Event Listener
Event - Missed Event

Parsing of HTML files happens synchronously and incrementally, meaning that the parser can pause at any point to let scripts run. It does mean that authors need to be careful to avoid hooking event handlers...



Share this page:
Follow us:
Task Runner