This answer is restricted. Please login to view the answer of this question.Login Now
A race condition occurs when two or more threads can access shared data and they try to change it at the same time. Because the thread scheduling algorithm can swap between threads at any time, you don’t know the order in which the threads will attempt to access the shared data. Therefore, the result of the change in data is dependent on the thread scheduling algorithm, i.e. both threads are “racing” to access/change the data.
To avoid race condition we need mutual exclusion.
Mutual Exclusion: It is some way of making sure that if one process is using a shared variable or file, the other process will be excluded from doing the somethings.
The difficulty in printer spooler occurs because process B started using one of the shared variables before process A was finished with it. If we could arrange matter such that no two processes were ever in there critical regions at at the same time, we could avoid race conditions.
Click here to submit your answer.