vault backup: 2025-03-12 10:49:27
This commit is contained in:
parent
6547be1a32
commit
484cb712c6
2 changed files with 20 additions and 4 deletions
|
@ -48,11 +48,27 @@ S.down() :=
|
|||
if S.counter < 0 then
|
||||
enter into S.queue
|
||||
S.t <- 0
|
||||
Enable interrupts
|
||||
SUSPEND
|
||||
else
|
||||
S.t <- 0
|
||||
Enable interrupts
|
||||
return
|
||||
|
||||
S.up() :=
|
||||
Disable interrupts
|
||||
wait S.t.test&set() = 0
|
||||
S.counter++
|
||||
if S.counter <= 0 then
|
||||
activate a proc from S.queue
|
||||
S.t <- 0
|
||||
Enable interrupts
|
||||
return
|
||||
```
|
||||
Same as before but we use test&set to actually ensure MUTEX (of course we could have used any other hardware MUTEX implementation seen so far).
|
||||
|
||||
#### (Single) Producer/Consumer
|
||||
It's a shared FIFO buffer of size k.
|
||||
- `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
|
||||
- `FREE/BUSY`: two semaphores that count thew number of free/busy cells of BUF, initialized at k and 0 respectively.
|
Loading…
Add table
Add a link
Reference in a new issue