From 5df57ffe73283777c16ddbc400c8ea57d08ce516 Mon Sep 17 00:00:00 2001 From: Marco Realacci Date: Wed, 12 Mar 2025 11:39:27 +0100 Subject: [PATCH] vault backup: 2025-03-12 11:39:27 --- .obsidian/workspace.json | 4 +-- Concurrent Systems/notes/4 - Semaphores.md | 39 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index bfe8edc..299ac83 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -34,9 +34,9 @@ "type": "pdf", "state": { "file": "Concurrent Systems/slides/class 4.pdf", - "page": 8, + "page": 10, "left": -23, - "top": 187, + "top": 122, "zoom": 0.652019002375297 }, "icon": "lucide-file-text", diff --git a/Concurrent Systems/notes/4 - Semaphores.md b/Concurrent Systems/notes/4 - Semaphores.md index d66924b..7d4d5a3 100644 --- a/Concurrent Systems/notes/4 - Semaphores.md +++ b/Concurrent Systems/notes/4 - Semaphores.md @@ -180,3 +180,42 @@ begin_write() := end_write() := GLOB_MUTEX.up() return +``` + +##### Strong priority to Readers +When a writer terminates, it activates the first reader, if there is any, or the first writer, otherwise. + +``` +GLOB_MUTEX and R_MUTEX and W_MUTEX semaphores init. at 1 +R a shared register init. at 0 + +begin_read() := end_read() := + come prima come prima + +begin_write() := + W_MUTEX.down() + GLOB_MUTEX.down() + return + +end_write() := + GLOB_MUTEX.up() + W_MUTEX.up() + return +``` + +##### Weak priority to Writers +``` +GLOB_MUTEX, PRIO_MUTEX, R_MUTEX and W_MUTEX semaphores init. at 1 R and W shared registers init. at 0 + +begin_read() := + PRIO_MUTEX.down() + R_MUTEX.down() + R++ + if R = 1 then + GLOB_MUTEX.down() + R_MUTEX.up() + PRIO_MUTEX.up() + return + +end_read() := +