vault backup: 2025-03-17 10:09:23
This commit is contained in:
parent
b593b97296
commit
a8b293d935
2 changed files with 30 additions and 8 deletions
16
.obsidian/workspace.json
vendored
16
.obsidian/workspace.json
vendored
|
@ -34,10 +34,10 @@
|
|||
"type": "pdf",
|
||||
"state": {
|
||||
"file": "Concurrent Systems/slides/class 4.pdf",
|
||||
"page": 17,
|
||||
"left": -36,
|
||||
"top": 91,
|
||||
"zoom": 0.4133016627078385
|
||||
"page": 18,
|
||||
"left": -26,
|
||||
"top": 163,
|
||||
"zoom": 0.57541567695962
|
||||
},
|
||||
"icon": "lucide-file-text",
|
||||
"title": "class 4"
|
||||
|
@ -196,7 +196,8 @@
|
|||
}
|
||||
],
|
||||
"direction": "horizontal",
|
||||
"width": 364.5
|
||||
"width": 364.5,
|
||||
"collapsed": true
|
||||
},
|
||||
"left-ribbon": {
|
||||
"hiddenItems": {
|
||||
|
@ -217,10 +218,10 @@
|
|||
},
|
||||
"active": "6edd4157a160e462",
|
||||
"lastOpenFiles": [
|
||||
"Concurrent Systems/slides/class 4.pdf",
|
||||
"Concurrent Systems/notes/4c - Dining Philosophers.md",
|
||||
"Concurrent Systems/notes/images/Pasted image 20250317100456.png",
|
||||
"Concurrent Systems/notes/4b - Monitors.md",
|
||||
"Concurrent Systems/notes/4c - Dining Philosophers.md",
|
||||
"Concurrent Systems/slides/class 4.pdf",
|
||||
"Concurrent Systems/slides/class 5.pdf",
|
||||
"HCIW/slides/4 HUI2016-6-forcefeedback.pdf",
|
||||
"HCIW/slides/3b Haptic slides.pdf",
|
||||
|
@ -251,7 +252,6 @@
|
|||
"Concurrent Systems/notes/images/Pasted image 20250304090219.png",
|
||||
"Concurrent Systems/notes/images/Pasted image 20250304090207.png",
|
||||
"Concurrent Systems/notes/images/Pasted image 20250304084901.png",
|
||||
"Concurrent Systems/notes/images/Pasted image 20250304084537.png",
|
||||
"Foundation of data science/notes/1 CV Basics.md",
|
||||
"Foundation of data science/notes/7 Autoencoders.md",
|
||||
"Foundation of data science/notes/6 PCA.md",
|
||||
|
|
|
@ -5,3 +5,25 @@ The first real practical example of a concurrent system.
|
|||
- a philosopher must pick up first one chopstick, then the second one, not both at once
|
||||
![[Pasted image 20250317100456.png|100]]
|
||||
|
||||
**PROBLEM:** *Devise a deadlock-free algorithm for allocating these limited resources (chopsticks) among several processes (philosophers).*
|
||||
|
||||
#### A wrong solution
|
||||
each chopstick is governed by a mutual exclusion semaphore that prevents any other philosopher from picking up the chopstick when it is already in use by another philosopher
|
||||
|
||||
```
|
||||
semaphore chopstick[5] initialized to 1
|
||||
Philosopher(i) :=
|
||||
while(1) do
|
||||
chopstick[i].down()
|
||||
chopstick[(i+1)%N].down()
|
||||
// eat
|
||||
chopstick[(i+1)%N].up()
|
||||
chopstick[i].up()
|
||||
```
|
||||
No two neighbors can eat simultaneously, but we can have a deadlock if all philosophers grab their right chopstick simultaneously.
|
||||
|
||||
#### Solution 1
|
||||
Give a number to all forks and always try with the smaller.
|
||||
All philosophers must first pick left and then right, except for the last one that first picks right and then left.
|
||||
|
||||
So there will be c
|
Loading…
Add table
Add a link
Reference in a new issue