Hi I have a global variable (my_var) initialized to zero and from the main thread another thread is created which only sets the global variable to one. After creating the secondary thread, the main thread waits for the global variable to be set to one like this:
while (0 == my_var);
Even if the global variable is set in the secondary thread, the main thread remains blocked forever in the while loop. If I use instead:
while (0 == my_var) { sleep(1); }
the main thread detects that the global variable has been set. Could someone explain what happens in the first case and why the global variable is not detected when it is set ?