diff --git a/README.md b/README.md index 7e0fc90a6f1204f027d6bd86f449e2de09b46e7c..95539366256ece0daf5c67dab204fb6c3a283b34 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