Next: semaphores
You eat lunch at 11:59 and Bob eats lunch at 12:01. Who ate lunch first? - You don’t know who ate lunch first, because your clocks could be wrong.
How can you guarantee that you will eat lunch before Bob tomorrow? - Tell him not to eat lunch until after you’ve called him. - Eat lunch, and then call Bob. - This risks starvation (Bob can’t eat until you call him, which you can sacrifice correctness for (tell him to eat at 12:30 his time anyway so he goes eventually)).
Thread A Thread B
print(‘yes’) print(‘no’)