Race Condition in Operating System | OS Tutorials YASH PAL, May 25, 2026May 25, 2026 In an Operating System Race condition is a situation in which multiple threads or processes read and write a shared data item, and the final result depends on the relative timing of their execution. To guard against the race condition, we need to ensure that only one process at a time can be manipulating the variable, and to make such a guarantee, we require that the processes be synchronized in some way.Race conditionConsider an example of a print spooler. When a process wants to print a file, it enters the file name in a special Spooler Directory. Another process, the printer daemon, periodically checks to see if there are any files to be printed, and if there are, it prints them and then removes their names from the directory.Suppose that the spooler directory has a very large number of slots numbered 0,1, 2,…, each one capable of holding a file name. Suppose there are two shared variables, out and in. Out points to the next file to be printed, and in points to the next free slot in the directory. Suppose slots 0 to 3 are empty and slots 4 to 6 are full. More or less simultaneously, processes A and B decide they want to queue a file for printing. It is shown in Figure 1.Figure 1: Race ConditionSuppose, process A reads in and stores the value 7 in a local variable called next-free-slot. After some time, process A terminates and switches to process B.Process B also reads in and gets a 7. It also stores it in its local variable next-free-slot. At this instant, both processes think that the next available slot is 7.A situation like this, where two or more processes are reading or writing some shared data and the final result depends on who runs precisely when, is called a race condition. engineering subjects Operating System Operating System