vault backup: 2025-03-12 11:04:27

This commit is contained in:
Marco Realacci 2025-03-12 11:04:27 +01:00
parent cc646c8e2a
commit d80a37f73e

View file

@ -93,4 +93,23 @@ B.consume() :=
> Reading from / writing into the buffer can be very expensive! > Reading from / writing into the buffer can be very expensive!
#### (Multiple) Producers/Consumers #### (Multiple) Producers/Consumers
**Accessing BUF in MUTEX slows down the implementation** **Accessing BUF in MUTEX slows down the implementation**, we would like to have the possibility to read and write from different cells **in parallel**.
- we use two arrays FULL and EMPTY of atomic boolean registers, initialized at ff (all zeros) and tt (all ones), respectively
- we have two extra semaphores SP and SC, both initialized at 1
```
B.produce(v) :=
FREE.down()
SP.down()
while not EMPTY[in] do
IN <- (IN+1) mod k
i <- IN
EMPTY[IN] <- ff
SP.up()
BUF[i] <- v
FULL[i] <- tt
BUSY.up()
return
```