vault backup: 2025-03-12 11:54:27
This commit is contained in:
parent
513c546ab8
commit
71114f1630
1 changed files with 29 additions and 3 deletions
|
@ -127,7 +127,32 @@ B.consume() :=
|
||||||
Thanks to the semaphores, we are sure that while loops will not go on forever! The loops starts only if there is at least a FREE / BUSY cell.
|
Thanks to the semaphores, we are sure that while loops will not go on forever! The loops starts only if there is at least a FREE / BUSY cell.
|
||||||
|
|
||||||
#### (Multiple) Producers/Consumers - Wrong solution
|
#### (Multiple) Producers/Consumers - Wrong solution
|
||||||
EXERCISE - will do later
|
**EXERCISE** this example is wrong
|
||||||
|
```
|
||||||
|
B.produce(v) :=
|
||||||
|
FREE.down()
|
||||||
|
SP.down()
|
||||||
|
i <- IN
|
||||||
|
IN <- (IN + 1) mod k
|
||||||
|
EMPTY[in] <- ff
|
||||||
|
SP.up()
|
||||||
|
BUF[i] <- v
|
||||||
|
FULL[i] <- tt
|
||||||
|
BUSY.up()
|
||||||
|
return
|
||||||
|
|
||||||
|
B.consume() :=
|
||||||
|
BUSY.down()
|
||||||
|
SC.down()
|
||||||
|
o <- OUT
|
||||||
|
OUT <- (OUT+1) mod k
|
||||||
|
FULL[OUT] <- ff
|
||||||
|
SC.up()
|
||||||
|
tmp <- BUF[o]
|
||||||
|
EMPTY[o] <- tt
|
||||||
|
FREE.up()
|
||||||
|
return tmp
|
||||||
|
```
|
||||||
|
|
||||||
#### The Readers/Writers problem
|
#### The Readers/Writers problem
|
||||||
- Several processes want to access a file
|
- Several processes want to access a file
|
||||||
|
@ -181,7 +206,7 @@ end_write() :=
|
||||||
GLOB_MUTEX.up()
|
GLOB_MUTEX.up()
|
||||||
return
|
return
|
||||||
```
|
```
|
||||||
If readers keeps arriving, they surpass writers. But when a writer terminates a
|
If readers keeps arriving, they surpass writers. But when a writer terminates it activates the first suspended process, which can be a reader or a writer.
|
||||||
##### Strong priority to Readers
|
##### Strong priority to Readers
|
||||||
When a writer terminates, it activates the first reader, if there is any, or the first writer, otherwise.
|
When a writer terminates, it activates the first reader, if there is any, or the first writer, otherwise.
|
||||||
|
|
||||||
|
@ -244,3 +269,4 @@ def end_write() :=
|
||||||
return
|
return
|
||||||
```
|
```
|
||||||
This is prioritizing writers as if there are writers waiting, they will be waiting at `GLOB_MUTEX.down()`. This semaphore is upped before `PRIO_MUTEX` which is the one that blocks readers.
|
This is prioritizing writers as if there are writers waiting, they will be waiting at `GLOB_MUTEX.down()`. This semaphore is upped before `PRIO_MUTEX` which is the one that blocks readers.
|
||||||
|
But writers won't be able to writer until there are no readers, if they keep coming, they will block the writers as `GLOB_MUTEX` will never be upped.
|
Loading…
Reference in a new issue