diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 3e18f76..0cd6713 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -13,12 +13,12 @@ "state": { "type": "markdown", "state": { - "file": "Concurrent Systems/notes/4b - Monitors.md", + "file": "Concurrent Systems/test/Untitled.md", "mode": "source", "source": false }, "icon": "lucide-file", - "title": "4b - Monitors" + "title": "Untitled" } }, { @@ -206,8 +206,8 @@ }, "active": "7c5b0ca6f7687800", "lastOpenFiles": [ - "Concurrent Systems/notes/4 - Semaphores.md", "Concurrent Systems/notes/4b - Monitors.md", + "Concurrent Systems/notes/4 - Semaphores.md", "Concurrent Systems/notes/5 - Software Transactional Memory.md", "Concurrent Systems/test/Untitled.md", "Concurrent Systems/notes/4c - Dining Philosophers.md", diff --git a/Concurrent Systems/test/Untitled.md b/Concurrent Systems/test/Untitled.md index e84129b..9081afa 100644 --- a/Concurrent Systems/test/Untitled.md +++ b/Concurrent Systems/test/Untitled.md @@ -33,4 +33,39 @@ end_write() := PRR_MUTEX.up() GLOB_MUTEX.up() return +``` + +``` +monitor RW_READERS := + AR, WR, AW, WW init at 0 + condition CR, CW, CR_PR + +operation begin_read() := + WR++ + if WW != 0 then + CR_PR.wait() + if AW != 0 then + CR.wait() + CR.signal() + AR++ + WR-- + +operation end_read() := + AR-- + if AR = 0 then + CW.signal() + +operation begin_write() := + WW++ + if (AR + AW != 0) then + CW.wait() + AW++ + WW-- + +operation end_write() := + AW-- + if WR > 0 then + CR.signal() + else + CW.signal() ``` \ No newline at end of file