what is a race condition code example
Example 1: race condition
A race condition occurs when two or more threads can access
shared data and they try to change it at the same time.
Because the thread scheduling algorithm can swap between
threads at any time, you don't know the order in which the
threads will attempt to access the shared data.
if (x == 5)
{
y = x * 2;
}
In order to prevent race condition,we need to obtain lock on shared variable.
Example 2: what is a race condition
if (x == 5)
{
y = x * 2;
}