From 5776ab1efbc6a0a8068891c57548ac7b8fdd13b7 Mon Sep 17 00:00:00 2001 From: Ida Made Revindra Dikta Mahendra <idamaderevindra05@gmail.com> Date: Fri, 28 Mar 2025 10:13:29 +0700 Subject: [PATCH] [DOCS]: Writing Reflection Subscriber-1 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7e0fc90..9553936 100644 --- a/README.md +++ b/README.md @@ -85,5 +85,8 @@ This is the place for you to write reflections: ### Mandatory (Subscriber) Reflections #### Reflection Subscriber-1 +In our design, we used an RwLock to protect the Vec of notifications because this lock allows multiple threads to read the data simultaneously while still ensuring exclusive access when writing. This is ideal for our scenario, where the system frequently reads notifications but only occasionally updates them. A Mutex, on the other hand, would restrict access to a single thread at any given time, even for read operations, which would unnecessarily slow down the system under heavy read loads. The RwLock thus provides a better balance between thread safety and performance in our application. + +Rust enforces strict safety rules around mutable static data to prevent race conditions and data corruption. Unlike Java, where static variables can be mutated freely via static methods, Rust requires that any global mutable state be managed carefully. By using the lazy_static library, we can initialize static variables like Vec and DashMap in a controlled and thread-safe manner. This approach avoids the risks associated with direct mutation and ensures that our program remains safe even in a concurrent environment, adhering to Rust’s core design principles of memory and thread safety. #### Reflection Subscriber-2 -- GitLab