I have a variable that is accessed from two threads. Do I need to use mutex when one thread is modifying it while the other is only reading it?
My understanding is that mutex is needed if both threads are writing to the same variable, but not for the case above as write happens only from one thread.
Unless the method modifying the object is atomic, you need mutex. In fact, even write is not atomic in Ruby. Cf. Read and write file atomically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With