diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 17dc80e..dba74c0 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -34,9 +34,9 @@ "type": "pdf", "state": { "file": "Concurrent Systems/slides/class 4.pdf", - "page": 3, + "page": 4, "left": -23, - "top": 298, + "top": 342, "zoom": 0.652019002375297 }, "icon": "lucide-file-text", @@ -217,10 +217,10 @@ }, "active": "6edd4157a160e462", "lastOpenFiles": [ + "Concurrent Systems/slides/class 4.pdf", + "Concurrent Systems/notes/4 - Semaphores.md", "Concurrent Systems/notes/3a - Hardware primitives & Lamport Bakery algorithm.md", "Concurrent Systems/notes/3b - Aravind's algorithm and improvements.md", - "Concurrent Systems/notes/4 - Semaphores.md", - "Concurrent Systems/slides/class 4.pdf", "Concurrent Systems/notes/images/Pasted image 20250310172134.png", "Concurrent Systems/notes/1b - Peterson algorithm.md", "Concurrent Systems/slides/class 3.pdf", diff --git a/Concurrent Systems/notes/4 - Semaphores.md b/Concurrent Systems/notes/4 - Semaphores.md index b758a9b..81fe07e 100644 --- a/Concurrent Systems/notes/4 - Semaphores.md +++ b/Concurrent Systems/notes/4 - Semaphores.md @@ -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. \ No newline at end of file