diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 41822b1..94d16d7 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -27,12 +27,12 @@ "state": { "type": "markdown", "state": { - "file": "Concurrent Systems/notes/10 - Implementing Consensus.md", + "file": "Concurrent Systems/test/Untitled.md", "mode": "source", "source": false }, "icon": "lucide-file", - "title": "10 - Implementing Consensus" + "title": "Untitled" } } ], @@ -207,14 +207,15 @@ }, "active": "e453bba00fdc57d6", "lastOpenFiles": [ - "Concurrent Systems/notes/9 - Consensus.md", - "Concurrent Systems/notes/8 - Enhancing Liveness Properties.md", + "Concurrent Systems/notes/4b - Monitors.md", "Concurrent Systems/notes/7- MUTEX-free concurrency.md", + "Concurrent Systems/notes/8 - Enhancing Liveness Properties.md", "Concurrent Systems/notes/6a - Alternatives to Atomicity.md", "Concurrent Systems/notes/6 - Atomicity.md", "Concurrent Systems/notes/5 - Software Transactional Memory.md", + "Concurrent Systems/notes/10 - Implementing Consensus.md", + "Concurrent Systems/notes/9 - Consensus.md", "Concurrent Systems/notes/4c - Dining Philosophers.md", - "Concurrent Systems/notes/4b - Monitors.md", "Concurrent Systems/notes/4 - Semaphores.md", "Concurrent Systems/notes/3b - Aravind's algorithm and improvements.md", "Concurrent Systems/notes/3a - Hardware primitives & Lamport Bakery algorithm.md", @@ -227,7 +228,6 @@ "Concurrent Systems/slides/class 9.pdf", "Concurrent Systems/slides/class 10.pdf", "Concurrent Systems/test", - "Concurrent Systems/notes/10 - Implementing Consensus.md", "HCIW/slides/Tangible User Interfaces.pdf", "Concurrent Systems/notes/images/Pasted image 20250401083747.png", "Concurrent Systems/notes/images/Pasted image 20250401092557.png", diff --git a/Concurrent Systems/test/Untitled.md b/Concurrent Systems/test/Untitled.md index 2993593..69c4ce0 100644 --- a/Concurrent Systems/test/Untitled.md +++ b/Concurrent Systems/test/Untitled.md @@ -34,3 +34,37 @@ end_write() := GLOB_MUTEX.up() return ``` + +``` +monitor RW_READERS := + AR, WR, AW, WW, LASTW init at 0 + condition CR, CW + +operation begin_read() := + if WW + AW != 0 then + CR.wait() + CR.signal() + AR++ + +operation end_read() := + AR-- + if AR = 0 then + CW.signal() + +operation begin_write() := + WW++ + LASTW <- i + CW.signal() # wakes eventually other waiting writers *they will return false* + if (AR + AW != 0) then + CW.wait() + if LASTW + AW++ + WW-- + +operation end_write() := + AW-- + if WW > 0 then + CW.signal() + else + CR.signal() +``` \ No newline at end of file