From fd489815caa0c550da72de40a1cc111179e54e4e Mon Sep 17 00:00:00 2001 From: rafliesa <rflisaa@gmail.com> Date: Fri, 28 Mar 2025 18:44:49 +0700 Subject: [PATCH] Reflection Subscriber-1 --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a4d436..cfcb403 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # Reflection Subscriber-1 ## 1.In this tutorial, we used RwLock<> to synchronise the use of Vec of Notifications. Explain why it is necessary for this case, and explain why we do not use Mutex<> instead? -Dengan menggunakan RwLock<>, kita memastikan bahwa proses konkurensi terjadi secara aman. Kita memastikan bahwa proses read diblok hanya ketika terjadi proses write. Berbeda dengan mutex yang hanya mengizinkan 1 thread untuk mengakses data dalam satu waktu. \ No newline at end of file +Dengan menggunakan RwLock<>, kita memastikan bahwa proses konkurensi terjadi secara aman. Kita memastikan bahwa proses read diblok hanya ketika terjadi proses write. Berbeda dengan mutex yang hanya mengizinkan 1 thread untuk mengakses data dalam satu waktu. + +## 2.In this tutorial, we used lazy_static external library to define Vec and DashMap as a “static” variable. Compared to Java where we can mutate the content of a static variable via a static function, why did not Rust allow us to do so? +Rust tidak mengizinkan hal tersebut untuk mencegah data race. Untuk mengatur variabel global static secara aman, rust mendorong developer untuk menggunakan Mutex<T> atau RwLock<T> yang sering kali digabungkan dengan lazy_static!. Pendekatan ini memastikan bahwa state global tetap thread-safe ketika sedang diakses oleh seluruh program. \ No newline at end of file -- GitLab