Please give a brief introduction of the terminology of Race Condition in Operating System.
@logan_white A race condition in operating system is an undesirable situation that occurs when a device or system attempts to perform two or more operations at the same time, but because of the nature of the device or system, the operations must be done in the proper sequence to be done correctly.
A race condition arises when concurrently executing code attempts to access a shared resource simultaneously, due to an error in the code / assumption about sequence of events / assumption about timing of events / assumption of exclusive access.
Most common example is simultaneous access to a file / shared memory (read/write, write/write) - a process reads/writes a file assuming that another process already finished writing into a file.
Another common example is reading from database with improper transaction isolation level.
Using proper IPC techniques (mutex/locks/semaphores) helps to reduce the risks of race conditions.
A race condition is anything where the outcome of a program depends on the relative ordering of execution of operations on two or more threads.
a race condition happens in multiprocess program, which asks for changing of same resource, such as :
for ( int i = 0; i < 10; i++ )
The x value print out is not a consistent , Mutual Exclusion and bounded waiting could solve this problem.
The situation of RACE CONDITION arises when several processes tries to access and manipulate the shared data (also called as Critical Section) concurrently. This concurrent access of Critical section will lead to data inconsistency and undesirable results.
Consider a kernel data structure that maintains list of all open files in the system. This list must be modified when the new file is opened or closed(adding the file to the list and removing file from the list).If two processes are opening file simultaneously then the concurrent update in this list will lead to race condition.
Source:- Operating System Principles by Galvin
A race happens when two or more threads of control simultaneously access a memory location with at least one of them writing to it.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.