Race conditions

A race condition is a situation in which the timing of the execution of threads causes an unexpected result. The order in which the threads finish their execution should not influence the overall result. In race conditions, the final result (or state) varies, depending on which thread finishes first. Bugs arising from race conditions are difficult to debug and reproduce, as they happen relatively rarely, and the timing of threads is important. During some program executions, we get expected results, while at other times, when a race condition is taking place, we get unexpected results.