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.
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 atau RwLock yang sering kali digabungkan dengan lazy_static!. Pendekatan ini memastikan bahwa state global tetap thread-safe ketika sedang diakses oleh seluruh program.