When two threads share a shared variable, a race condition occurs. The first thread tries to write the last value of the variable, and the second thread races to see which one can do so.