vault backup: 2025-03-10 08:44:43

This commit is contained in:
Marco Realacci 2025-03-10 08:44:43 +01:00
parent 8b41fce975
commit 4979a0eed2
2 changed files with 50 additions and 4 deletions

View file

@ -49,9 +49,9 @@
"type": "pdf",
"state": {
"file": "Concurrent Systems/slides/class 3.pdf",
"page": 1,
"page": 5,
"left": -9,
"top": 169,
"top": 186,
"zoom": 0.6
},
"icon": "lucide-file-text",

View file

@ -23,7 +23,7 @@ X.test&set() :=
(the function is implemented in an atomic way by the hardware by suspending the interruptions!)
```
###### How do we use it?
###### How do we use it for MUTEX?
```
lock() :=
wait X.test&set() = 0
@ -44,4 +44,50 @@ X.swap(v) :=
tmp <- X
X <- v
return tmp
```
###### How do we use it for MUTEX?
```
lock() :=
wait X.swap(1) = 0
return
unlock() :=
X <- 0
return
```
#### Compare&swap
```
X boolean register
X.compare&swap(old, new) :=
if X = old then
X <- new
return true
return false
```
###### How do we use it for MUTEX?
```
Initialize X at 0
lock() :=
wait X.compare&swap(0, 1) = true
return
unlock() :=
X <- 0
return
```
#### Fetch&add
Up to now, all solutions enjoy deadlock freedom, but allow for starvation. So let's use Round Robin to promote the liveness property!
Let X be an integer register; the Fetch&add primitive is implemented as follows:
```
X.fetch&add(v) :=
tmp <- X
X <- X+v
return tmp
```