Skip to content

Commit 2e5a4a6

Browse files
Update README.md
1 parent f0c17d5 commit 2e5a4a6

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

DiningPhilosophers/README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
# SwiftDiningPhilosophers
22
Dining philosophers problem Algorithm implemented in Swift (concurrent algorithm design to illustrate synchronization issues and techniques for resolving them using GCD and Semaphore in Swift)
33

4-
Written by Jacopo Mangiavacchi
4+
Written for Swift Algorithm Club by Jacopo Mangiavacchi
55

66

7-
# from https://en.wikipedia.org/wiki/Dining_philosophers_problem
7+
# Introduction
88

99
In computer science, the dining philosophers problem is an example problem often used in concurrent algorithm design to illustrate synchronization issues and techniques for resolving them.
1010

1111
It was originally formulated in 1965 by Edsger Dijkstra as a student exam exercise, presented in terms of computers competing for access to tape drive peripherals. Soon after, Tony Hoare gave the problem its present formulation.
1212

1313
This Swift implementation is based on the Chandy/Misra solution and it use GCD Dispatch and Semaphone on Swift cross platform
14+
15+
# Problem statement
16+
17+
Five silent philosophers sit at a round table with bowls of spaghetti. Forks are placed between each pair of adjacent philosophers.
18+
19+
Each philosopher must alternately think and eat. However, a philosopher can only eat spaghetti when they have both left and right forks. Each fork can be held by only one philosopher and so a philosopher can use the fork only if it is not being used by another philosopher. After an individual philosopher finishes eating, they need to put down both forks so that the forks become available to others. A philosopher can take the fork on their right or the one on their left as they become available, but cannot start eating before getting both forks.
20+
21+
Eating is not limited by the remaining amounts of spaghetti or stomach space; an infinite supply and an infinite demand are assumed.
22+
23+
The problem is how to design a discipline of behavior (a concurrent algorithm) such that no philosopher will starve; i.e., each can forever continue to alternate between eating and thinking, assuming that no philosopher can know when others may want to eat or think.
24+
25+
This is an illustration of an dinining table:
26+
27+
![Dining Philosophers table](https://upload.wikimedia.org/wikipedia/commons/7/7b/An_illustration_of_the_dining_philosophers_problem.png)
28+
29+
30+
31+
# See also
32+
33+
Dining Philosophers on Wikipedia https://en.wikipedia.org/wiki/Dining_philosophers_problem
34+
35+
Written for Swift Algorithm Club by Jacopo Mangiavacchi

0 commit comments

Comments
 (0)