vault backup: 2025-03-12 10:54:27

This commit is contained in:
Marco Realacci 2025-03-12 10:54:27 +01:00
parent 484cb712c6
commit 60d4e7ea2d
2 changed files with 19 additions and 2 deletions

View file

@ -36,7 +36,7 @@
"file": "Concurrent Systems/slides/class 4.pdf", "file": "Concurrent Systems/slides/class 4.pdf",
"page": 4, "page": 4,
"left": -23, "left": -23,
"top": 342, "top": 187,
"zoom": 0.652019002375297 "zoom": 0.652019002375297
}, },
"icon": "lucide-file-text", "icon": "lucide-file-text",

View file

@ -71,4 +71,21 @@ Same as before but we use test&set to actually ensure MUTEX (of course we could
It's a shared FIFO buffer of size k. It's a shared FIFO buffer of size k.
- `BUF[0,…,k-1]`: generic registers (not even safe) accessed in MUTEX - `BUF[0,…,k-1]`: generic registers (not even safe) accessed in MUTEX
- `IN/OUT` : two variables pointing to locations in `BUF` to (circularly) insert/remove items, both initialized at 0 - `IN/OUT` : two variables pointing to locations in `BUF` to (circularly) insert/remove items, both initialized at 0
- `FREE/BUSY`: two semaphores that count thew number of free/busy cells of BUF, initialized at k and 0 respectively. - `FREE/BUSY`: two semaphores that count thew number of free/busy cells of `BUF`, initialized at k and 0 respectively.
```
B.produce(v) :=
FREE.down() # blocking if FREE becomes negative
BUF[IN] <- v
IN <- (IN+1) mod k # mod k since it is circular
BUSY.up() # "there is something to consume"
return
B.consume() :=
BUSY.down() # it blocks if there is nothing to consume
tmp <- BUF[OUT]
OUT <- (OUT+1) mod k
FREE.up()
return tmp
```