vault backup: 2025-03-04 08:29:45
This commit is contained in:
parent
8a8d2020d2
commit
62d5142515
3 changed files with 24 additions and 2 deletions
5
.obsidian/workspace.json
vendored
5
.obsidian/workspace.json
vendored
|
@ -36,9 +36,9 @@
|
||||||
"type": "pdf",
|
"type": "pdf",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Concurrent Systems/slides/class 2.pdf",
|
"file": "Concurrent Systems/slides/class 2.pdf",
|
||||||
"page": 1,
|
"page": 2,
|
||||||
"left": -23,
|
"left": -23,
|
||||||
"top": 72,
|
"top": 542,
|
||||||
"zoom": 0.6796318289786224
|
"zoom": 0.6796318289786224
|
||||||
},
|
},
|
||||||
"icon": "lucide-file-text",
|
"icon": "lucide-file-text",
|
||||||
|
@ -220,6 +220,7 @@
|
||||||
},
|
},
|
||||||
"active": "802d9ec58484849d",
|
"active": "802d9ec58484849d",
|
||||||
"lastOpenFiles": [
|
"lastOpenFiles": [
|
||||||
|
"Pasted image 20250304082459.png",
|
||||||
"Concurrent Systems/slides/class 2.pdf",
|
"Concurrent Systems/slides/class 2.pdf",
|
||||||
"Concurrent Systems/notes/Lezione2.md",
|
"Concurrent Systems/notes/Lezione2.md",
|
||||||
"Concurrent Systems/notes/Lezione1.md",
|
"Concurrent Systems/notes/Lezione1.md",
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
Peterson's algorithm cost $O(n^2)$
|
||||||
|
A first way to reduce this cost is by using a tournament of MUTEX between pairs of processes:
|
||||||
|
![[Pasted image 20250304082459.png|350]]
|
||||||
|
|
||||||
|
Of course this is a binary tree, and the height of a binary tree is logaritmic to the number of leaves. A process then wins after $\lceil \log_{2}n \rceil$ competitions $\to O(\log n)$ cost.
|
||||||
|
|
||||||
|
But we can do better. Let's see an idea of a constant-time algorithm.
|
||||||
|
|
||||||
|
```
|
||||||
|
Initialize Y at ⊥, X at any value (e.g., 0)
|
||||||
|
|
||||||
|
lock(i) :=
|
||||||
|
x <- i
|
||||||
|
if Y != ⊥ then FAIL
|
||||||
|
else Y <- i
|
||||||
|
if X = i then return
|
||||||
|
else fail
|
||||||
|
|
||||||
|
unlock(i) :=
|
||||||
|
Y <- ⊥
|
||||||
|
return
|
BIN
Pasted image 20250304082459.png
Normal file
BIN
Pasted image 20250304082459.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 92 KiB |
Loading…
Reference in a new issue