Concurrency - Race Condition (Concurrency Problem)

Data System Architecture

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
Imperative Vs Functional
Code - Functional programming (FP) - Collection Operations

Functional programming (FP) defines standard operations on collections. It is a declarative paradigm that treats computation as the evaluation of mathematical functions. Most of the operations, you perform...
Data System Architecture
Concurrency - Mutual Exclusion

Mutual Exclusion means that two threads or process cannot at the same time access the same resource (ie method, class, file, ...) in order to prevent race conditions. A lock (also known as mutex) is...
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....
Data System Architecture
Data Concurrency - Critical Section (Protected Region)

A critical section is the parts of a program (piece of code) that cannot be executed by more than one process (thread) at a time. It's also known as: a critical region or protected section A critical...
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...
Card Puncher Data Processing
Go - Minimal HTTP Server

This article is showing you how to create a minimal HTTP server. Main handler echoes the Path component of the requested URL. If two concurrent requests try to update count at the same time,...
Data System Architecture
Phenomena - Data problem (Concurrency Problem/ Data Corruption)

Because of a race condition, when several transactions concurrently read from and write to a file, variable or database, the following data problems called phenomena can arise: The isolation...
Data System Architecture
Process - Isolation

Isolation is the I in ACID, and it describes how an application protect itself from concurrency problems (race conditions) Olivia...
Data System Architecture
State - Mutable

A state who is mutable can be changed. Mutation happens with mutator method: in CRUD term, they are known as Create, Update, Delete at a object level, they are known as the mutator method (ie set,...
Data System Architecture
Thread Synchronizaton - Problem

In concurrency, the only big is known as a race condition where two threads are concurring for the same state. Sleeping_barber_problem: - ipc and synchronization problem when there is no customer,...



Share this page:
Follow us:
Task Runner