Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit fd489815 authored by rafliesa's avatar rafliesa
Browse files

Reflection Subscriber-1

parent de79a806
No related branches found
No related tags found
No related merge requests found
# Reflection Subscriber-1 # 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? ## 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. 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
## 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment