Modern dining philosophers
The eat tasks, however, have synchronization conditions, based on the forks near each philosopher. This diagram provides a good approximation of the problem, but it leaves one important detail out: what happens if a philosopher cannot pick up the forks to start eating? That’s the only framework implementation needed to start solving complex concurrency problems using tasks (well, dining philosophers is not exactly a complex problem, but still…). Looking at the implementation, things are relatively straightforward:
Let’s approach now the dining philosophers problem by starting to look at the abstraction. If we create a number of different philosophers, with some dining protocol, we can obtain an output similar to this:
In this output, we mark with an eating task, with a pure thinking task, with a thinking task resulting after failing to eat and with the leaving task.
Source: lucteo.ro