It is the last working day of the month. In one hour a bank's core system posts a few lakh salary credits, and every credit must also send an SMS: "Tk 45,000 has been credited to your account." Posting a credit takes a few milliseconds; handing the SMS to the telecom gateway takes a few hundred.
If the poster waited for every SMS, salaries would trickle in at the speed of the gateway. So the two cannot work hand in hand. Between them sits a waiting line of messages, and two awkward questions appear at once. What should the poster do when the line is full? And what happens if the poster and the sender touch the line in the same instant?
That is the first of four puzzles which every operating-system book keeps coming back to: this waiting line; many readers and a few writers around one table of exchange rates; five workers who each need two tools, with one tool between neighbours; and a barber shop with a sleeping barber. They are the classic synchronization problems. Each is a pattern you will meet again in real software, so learn it once, with the way it goes wrong, and you can recognise it in a new question in a minute.
By the end you will be able to write the bounded buffer with three semaphores and say why swapping two lines freezes it, and write it again as a monitor. You will solve readers–writers three ways and say who starves in each. You will take five philosophers from a deadlock (a freeze in which each waits for the other) to four working fixes. You will follow the sleeping barber through a schedule by hand, and spot which problem a new description is hiding. And you will know what Java and Python give you, so that you rarely write all this by hand.
Semaphores, mutexes and monitors came in the previous lesson; I recall each in a sentence. Every program here was compiled and run, and the outputs are real.