Data Races
Since the order of execution of each thread in MIMD is random, a thread-parallelized process may be subject to data races, where multiple threads access shared data concurrently, thereby leading to inconsistent or unexpected results.
Data races can be handled using:
- Atomic (indivisible) operations, which are sequences of low-level operations that execute reads and writes to memory at the same time, without being interrupted by any other process in between their execution.
- Locks, which allow only one thread to access and modify a state at a time. Code surrounded by a lock is called a critical section, and it becomes serial (cannot be paralellized). Locks are implemented using atomic operations.
Examples
Data Races in C