Search code examples
multithreadingrustmutex

How to properly manage multithreading read and write access in Rust?


I'm kind of confused by Arc and Mutex in rust. My problem is the following: The program should use n+1 threads, where only 1 thread has write access to data and the other n threads can only read data. How can I achieve this in rust?


Solution

  • Use RwLock. With it, readers don't block each other (but writers still block readers and readers block writers).