What is a race condition?
The situation when the process is critically dependent on the sequence or timing of other events.
For example,Processor A and processor B both needs identical resource for their execution.
How do you detect them?
There are tools to detect race condition automatically:
How do you handle them?
Race condition can be handled by Mutex or Semaphores. They act as a lock allows a process to acquire a resource based on certain requirements to prevent race condition.
How do you prevent them from occurring?
There are various ways to prevent race condition, such as Critical Section Avoidance.
- No two processes simultaneously inside their critical regions. (Mutual Exclusion)
- No assumptions are made about speeds or the number of CPUs.
- No process running outside its critical region which blocks other processes.
- No process has to wait forever to enter its critical region. (A waits for B resources, B waits for C resources, C waits for A resources)