Thread Coordination
Coordination Between Workers
-
Problem:
- Worker A is writing a document
- Worker A needs an image that Worker B is producing
- Worker A cannot continue until Worker B has finished
-
One solution is to introduce a manager
- The manager coordinates the two workers
Solution:
-
Worker B tells the manager when they have finished
-
The manager tells Worker A to resume work
- B is working
- A is waiting
- B finishes their work
- B tells manager
- Manager tells A to resume
- A resumes work
-
Similar situations arise with threads
-
E.g. A program which is performing a download
- One thread fetches the data over the network
- Another thread displays a progress bar
- A third thread will process the data when the download is complete