Answer the question
In order to leave comments, you need to log in
Ruby: Is there a lock on a resource on a thread while writing?
A multi-threaded application is planned, in which several threads will read a variable,
and sometimes this variable needs to be overwritten.
This means that this variable is required not to be blocked when reading from several threads, but when trying to write, it is blocked for everyone except the writing thread.
Is it possible to do this with Ruby?
I’m not “on you” with threads and ruby, I figured out only the simplest example of using mutexes.
somewhere I read about RWmutex, so I realized that I just need them.
-Is there RWmutex in ruby or is it possible to do something like that by other means?
- if possible - poke where to dig (or an example, the simplest))) )
Is there such a thing in Python? I don't know him either, so python can also be used..
Answer the question
In order to leave comments, you need to log in
it is not clear why you did not guess the standard mutexes . Threads will only block when trying to seize power when they are not supposed to. That is, only when recording. When reading, block if necessary so that the threads always have up-to-date data - then semaphores.
And so here is a rather interesting solution based on atomic operations.
Is there such a thing in Python?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question