@@ -7,21 +7,22 @@ called ‘the dining philosophers’. It was originally conceived by Dijkstra in
7
7
[ paper ] : http://www.usingcsp.com/cspbook.pdf
8
8
9
9
> In ancient times, a wealthy philanthropist endowed a College to accommodate
10
- > five eminent philosophers. Each philosopher had a room in which she could
10
+ > five eminent philosophers. Each philosopher had a room in which [ they ] could
11
11
> engage in her professional activity of thinking; there was also a common
12
12
> dining room, furnished with a circular table, surrounded by five chairs, each
13
13
> labelled by the name of the philosopher who was to sit in it. They sat
14
14
> anticlockwise around the table. To the left of each philosopher there was
15
15
> laid a golden fork, and in the centre stood a large bowl of spaghetti, which
16
- > was constantly replenished. A philosopher was expected to spend most of her
17
- > time thinking; but when she felt hungry, she went to the dining room, sat down
18
- > in her own chair, picked up her own fork on her left, and plunged it into the
19
- > spaghetti. But such is the tangled nature of spaghetti that a second fork is
20
- > required to carry it to the mouth. The philosopher therefore had also to pick
21
- > up the fork on her right. When she was finished she would put down both her
22
- > forks, get up from her chair, and continue thinking. Of course, a fork can be
23
- > used by only one philosopher at a time. If the other philosopher wants it, she
24
- > just has to wait until the fork is available again.
16
+ > was constantly replenished. A philosopher was expected to spend most of
17
+ > [ their] time thinking; but when [ they] felt hungry, [ they] went to the dining
18
+ > room, sat down in [ thier] own chair, picked up [ their] own fork on her left,
19
+ > and plunged it into the spaghetti. But such is the tangled nature of
20
+ > spaghetti that a second fork is required to carry it to the mouth. The
21
+ > philosopher therefore had also to pick up the fork on [ their] right. When
22
+ > [ they] was finished [ they] would put down both [ their] forks, get up from her
23
+ > chair, and continue thinking. Of course, a fork can be used by only one
24
+ > philosopher at a time. If the other philosopher wants it, [ they] just [ have]
25
+ > to wait until the fork is available again.
25
26
26
27
This classic problem shows off a few different elements of concurrency. The
27
28
reason is that it's actually slightly tricky to implement: a simple
@@ -60,10 +61,10 @@ impl Philosopher {
60
61
}
61
62
62
63
fn main () {
63
- let p1 = Philosopher :: new (" Baruch Spinoza " );
64
+ let p1 = Philosopher :: new (" Judith Butler " );
64
65
let p2 = Philosopher :: new (" Gilles Deleuze" );
65
66
let p3 = Philosopher :: new (" Karl Marx" );
66
- let p4 = Philosopher :: new (" Friedrich Nietzsche " );
67
+ let p4 = Philosopher :: new (" Emma Goldman " );
67
68
let p5 = Philosopher :: new (" Michel Foucault" );
68
69
}
69
70
```
@@ -159,10 +160,10 @@ look at `main()` again:
159
160
# }
160
161
#
161
162
fn main () {
162
- let p1 = Philosopher :: new (" Baruch Spinoza " );
163
+ let p1 = Philosopher :: new (" Judith Butler " );
163
164
let p2 = Philosopher :: new (" Gilles Deleuze" );
164
165
let p3 = Philosopher :: new (" Karl Marx" );
165
- let p4 = Philosopher :: new (" Friedrich Nietzsche " );
166
+ let p4 = Philosopher :: new (" Emma Goldman " );
166
167
let p5 = Philosopher :: new (" Michel Foucault" );
167
168
}
168
169
```
@@ -176,7 +177,7 @@ that `new()` function, it would look like this:
176
177
# name : String ,
177
178
# }
178
179
fn main () {
179
- let p1 = Philosopher { name : " Baruch Spinoza " . to_string () };
180
+ let p1 = Philosopher { name : " Judith Butler " . to_string () };
180
181
let p2 = Philosopher { name : " Gilles Deleuze" . to_string () };
181
182
let p3 = Philosopher { name : " Karl Marx" . to_string () };
182
183
let p4 = Philosopher { name : " Friedrich Nietzche" . to_string () };
@@ -211,10 +212,10 @@ impl Philosopher {
211
212
212
213
fn main () {
213
214
let philosophers = vec! [
214
- Philosopher :: new (" Baruch Spinoza " ),
215
+ Philosopher :: new (" Judith Butler " ),
215
216
Philosopher :: new (" Gilles Deleuze" ),
216
217
Philosopher :: new (" Karl Marx" ),
217
- Philosopher :: new (" Friedrich Nietzsche " ),
218
+ Philosopher :: new (" Emma Goldman " ),
218
219
Philosopher :: new (" Michel Foucault" ),
219
220
];
220
221
@@ -247,10 +248,10 @@ mention they’re done eating. Running this program should give you the followin
247
248
output:
248
249
249
250
``` text
250
- Baruch Spinoza is done eating.
251
+ Judith Butler is done eating.
251
252
Gilles Deleuze is done eating.
252
253
Karl Marx is done eating.
253
- Friedrich Nietzsche is done eating.
254
+ Emma Goldman is done eating.
254
255
Michel Foucault is done eating.
255
256
```
256
257
@@ -285,10 +286,10 @@ impl Philosopher {
285
286
286
287
fn main () {
287
288
let philosophers = vec! [
288
- Philosopher :: new (" Baruch Spinoza " ),
289
+ Philosopher :: new (" Judith Butler " ),
289
290
Philosopher :: new (" Gilles Deleuze" ),
290
291
Philosopher :: new (" Karl Marx" ),
291
- Philosopher :: new (" Friedrich Nietzsche " ),
292
+ Philosopher :: new (" Emma Goldman " ),
292
293
Philosopher :: new (" Michel Foucault" ),
293
294
];
294
295
@@ -323,14 +324,14 @@ simulate the time it takes a philosopher to eat.
323
324
If you run this program, you should see each philosopher eat in turn:
324
325
325
326
``` text
326
- Baruch Spinoza is eating.
327
- Baruch Spinoza is done eating.
327
+ Judith Butler is eating.
328
+ Judith Butler is done eating.
328
329
Gilles Deleuze is eating.
329
330
Gilles Deleuze is done eating.
330
331
Karl Marx is eating.
331
332
Karl Marx is done eating.
332
- Friedrich Nietzsche is eating.
333
- Friedrich Nietzsche is done eating.
333
+ Emma Goldman is eating.
334
+ Emma Goldman is done eating.
334
335
Michel Foucault is eating.
335
336
Michel Foucault is done eating.
336
337
```
@@ -366,10 +367,10 @@ impl Philosopher {
366
367
367
368
fn main () {
368
369
let philosophers = vec! [
369
- Philosopher :: new (" Baruch Spinoza " ),
370
+ Philosopher :: new (" Judith Butler " ),
370
371
Philosopher :: new (" Gilles Deleuze" ),
371
372
Philosopher :: new (" Karl Marx" ),
372
- Philosopher :: new (" Friedrich Nietzsche " ),
373
+ Philosopher :: new (" Emma Goldman " ),
373
374
Philosopher :: new (" Michel Foucault" ),
374
375
];
375
376
@@ -458,11 +459,11 @@ We have multi-threading!
458
459
``` text
459
460
Gilles Deleuze is eating.
460
461
Gilles Deleuze is done eating.
461
- Friedrich Nietzsche is eating.
462
- Friedrich Nietzsche is done eating.
462
+ Emma Goldman is eating.
463
+ Emma Goldman is done eating.
463
464
Michel Foucault is eating.
464
- Baruch Spinoza is eating.
465
- Baruch Spinoza is done eating.
465
+ Judith Butler is eating.
466
+ Judith Butler is done eating.
466
467
Karl Marx is eating.
467
468
Karl Marx is done eating.
468
469
Michel Foucault is done eating.
@@ -532,10 +533,10 @@ fn main() {
532
533
]});
533
534
534
535
let philosophers = vec! [
535
- Philosopher :: new (" Baruch Spinoza " , 0 , 1 ),
536
+ Philosopher :: new (" Judith Butler " , 0 , 1 ),
536
537
Philosopher :: new (" Gilles Deleuze" , 1 , 2 ),
537
538
Philosopher :: new (" Karl Marx" , 2 , 3 ),
538
- Philosopher :: new (" Friedrich Nietzsche " , 3 , 4 ),
539
+ Philosopher :: new (" Emma Goldman " , 3 , 4 ),
539
540
Philosopher :: new (" Michel Foucault" , 0 , 4 ),
540
541
];
541
542
@@ -643,10 +644,10 @@ count will go up, and when each thread ends, it will go back down.
643
644
644
645
``` rust,ignore
645
646
let philosophers = vec![
646
- Philosopher::new("Baruch Spinoza ", 0, 1),
647
+ Philosopher::new("Judith Butler ", 0, 1),
647
648
Philosopher::new("Gilles Deleuze", 1, 2),
648
649
Philosopher::new("Karl Marx", 2, 3),
649
- Philosopher::new("Friedrich Nietzsche ", 3, 4),
650
+ Philosopher::new("Emma Goldman ", 3, 4),
650
651
Philosopher::new("Michel Foucault", 0, 4),
651
652
];
652
653
```
@@ -679,12 +680,12 @@ and so you’ll get some output like this:
679
680
680
681
``` text
681
682
Gilles Deleuze is eating.
682
- Friedrich Nietzsche is eating.
683
- Friedrich Nietzsche is done eating.
683
+ Emma Goldman is eating.
684
+ Emma Goldman is done eating.
684
685
Gilles Deleuze is done eating.
685
- Baruch Spinoza is eating.
686
+ Judith Butler is eating.
686
687
Karl Marx is eating.
687
- Baruch Spinoza is done eating.
688
+ Judith Butler is done eating.
688
689
Michel Foucault is eating.
689
690
Karl Marx is done eating.
690
691
Michel Foucault is done eating.
0 commit comments