vault backup: 2025-03-12 10:39:14
This commit is contained in:
parent
7691811801
commit
fb56bcc453
2 changed files with 28 additions and 4 deletions
4
.obsidian/workspace.json
vendored
4
.obsidian/workspace.json
vendored
|
@ -34,9 +34,9 @@
|
||||||
"type": "pdf",
|
"type": "pdf",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Concurrent Systems/slides/class 4.pdf",
|
"file": "Concurrent Systems/slides/class 4.pdf",
|
||||||
"page": 1,
|
"page": 2,
|
||||||
"left": -23,
|
"left": -23,
|
||||||
"top": 50,
|
"top": 165,
|
||||||
"zoom": 0.652019002375297
|
"zoom": 0.652019002375297
|
||||||
},
|
},
|
||||||
"icon": "lucide-file-text",
|
"icon": "lucide-file-text",
|
||||||
|
|
|
@ -4,5 +4,29 @@
|
||||||
**Semaphore:** is a shared counter S accessed via primitives $up$ and $down$ s.t.:
|
**Semaphore:** is a shared counter S accessed via primitives $up$ and $down$ s.t.:
|
||||||
- is initialized at s0 >= 0
|
- is initialized at s0 >= 0
|
||||||
- it is alwayz >= 0
|
- it is alwayz >= 0
|
||||||
- up atomically increases S
|
- *up* atomically increases S
|
||||||
- down atomically decreases S if it is not 0, otherwise the proce
|
- *down* atomically decreases S if it is not 0, otherwise the calling process is blocked and waits.
|
||||||
|
|
||||||
|
Main use: **prevent busy waiting**: suspend processes that cannot perform *down*.
|
||||||
|
|
||||||
|
**Strong semaphore:** if uses a FIFO policy for blocking/unblocking, otherwise it's **weak**.
|
||||||
|
**Binary semaphore:** if it is at most 1 (also *up* are blocking).
|
||||||
|
|
||||||
|
A semaphore needs two underlying objects:
|
||||||
|
- a counter initialized at s0 that can also become negative
|
||||||
|
- a data structure (typically a queue), initially empty, to store suspended processes.
|
||||||
|
|
||||||
|
#### Ideal implementation
|
||||||
|
```
|
||||||
|
S.down() :=
|
||||||
|
S.counter--
|
||||||
|
if S.counter < 0 then
|
||||||
|
enter into S.queue
|
||||||
|
SUSPEND
|
||||||
|
return
|
||||||
|
|
||||||
|
S.up() :=
|
||||||
|
S.counter++
|
||||||
|
if S.counter <= 0 then
|
||||||
|
activate a proc from S.queue
|
||||||
|
return
|
Loading…
Reference in a new issue