1.21 int first= 1 /* shared variable*/ Example : race condition /* thread 1 */ if (first) { first--; task1(); } else { task2(); } /* thread 2 */ if (first) { first--; task1(); } else { task2(); } task1task2 Thread 1Thread 2 Thread 1 Thread 1 and Thread 2-- WRONG RESULT Programmer goal: use first boolean to distribute task 1 and task 2 between two threads.
{}