A race condition is an unwanted situation in which a program
attempts to perform two or more operations at the same time, but
because of the logic of the program, the operations have to be
performed in proper sequence to run the program correctly.
Since it is an undesirable behavior, it is considered as a bug in
code.
Most of the time race condition occurs in “check then act” scenario.
Both threads check and act on same value. But one of the threads
acts in between check and act. See this example to understand race
condition.
if (x == 3) // Check
{
y = x * 5; // Act
// If another thread changes x
// between "if (x == 3)” and "y = x * 5”,
// then y will not be equal to 15.
}
https://www.techtarget.com/searchstorage/definition/race-condition