What is a Race Condition?
Race conditions have to do with attempts by a system or individual device to engage in multitasking. Generally, a race condition exists when the system is attempting to process two or more different operations simultaneously, but is unable to do so. The reason for the failure is that the operations are not lined up in the proper sequence, a circumstance can lead to the system shutting down. While many different devices are configured to allow multitasking, there is still an internal process that creates a hierarchy of functions. In order for certain functions to take place, other functions must occur beforehand. While the end user perceives that all the functions may appear to be taking place at the same time, this is not necessarily the case. A race condition is created when two or more operations are vying with each other to reach completion ahead of the other operations. When all the individual functions are properly arranged, this leads to the successful execution of all the functi
A race condition occurs when 2 or more threads are able to access shared data and they try to change it at the same time. Because the thread scheduling algorithm can swap between threads at any point, you don’t kow the order at 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. Often problems occur when one thread does a “check-then-act” (e.g. “check” if the value is X, and then “act” to do something that depends on the value being X) and another thread does something to the value inbetween the “check” and the “act”.