• Race conditions are situations where two or more processes reads or writes some shared data at the same time and the final result is incorrect. 
  • Final result may be different according to order of completion of competing processes. 
  • let us consider a simple but common example: a print spooler. When a process wants to print a file, it enters the file name in a special spooler directory. 
  • Another process 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.
  • Consider the situation given in figure below, where in and out are two shared variables.
  • Process A reads value of in(i.e. 7) but before inserting the name of the document to be printed in index 7, the CPU decides to schedule process B. 
  • Now, process B also reads in, and also gets 7. Process B now continues to run and stores the name of its file in slot 7 and updates in to be an 8. 



  • After some time process A runs again. It looks at value of in stored in its local variable and finds a 7 there, and writes its file name in slot 7.Then it increments value of in and sets in to 8.The printer daemon will not notice anything wrong, but process B will never receive any output. Situations like this are called race conditions.