In: Computer Science
Why does a race condition occur? What is the solution for the race condition?
//if you have any query then comment below.please rate the answer
In Operating system the race condition occurs when the two or more threads(process) can access same (shared) data and they try to change it at the same time.
It is happening because the thread scheduling algorithm can swap
between threads at the 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, then the both treads want to change the data that's why
it is called race condition.
yes, we need to avoid it and use serialization of memory or storage
access. This means if read and write commands are received close
together, the read command is executed and completed first by
default.