vault backup: 2025-03-03 10:26:24
This commit is contained in:
parent
8fa222cf5f
commit
e9dd86ab87
1 changed files with 16 additions and 2 deletions
|
@ -186,10 +186,24 @@ b) `AFTER_YOU = 1`, this is possible only with the following interleaving:
|
|||
### Peterson algorithm ($n$ processes)
|
||||
- FLAG now has $n$ levels (from 0 to n-1)
|
||||
- level 0 means down
|
||||
- level >0 means inv
|
||||
- level >0 means involved in the lock
|
||||
- Every level has its own AFTER_YOU
|
||||
|
||||
```
|
||||
Initialize FLAG[i] to 0, for all i
|
||||
|
||||
lock
|
||||
lock(i) :=
|
||||
for lev = 1 to n-1 do
|
||||
FLAG[i] <- lev
|
||||
AFTER_YOU[lev] <- i
|
||||
wait (∀k!=i, FLAG[k] < lev
|
||||
OR AFTER_YOU[lev] != i)
|
||||
return
|
||||
|
||||
unlock(i) :=
|
||||
FLAG[i] <- 0
|
||||
return
|
||||
```
|
||||
We say that pi is at level h when it exits from the h-th wait -> a process at level h is at any level <= h
|
||||
|
||||
##### MUTE
|
Loading…
Reference in a new issue