Answer the question
In order to leave comments, you need to log in
Thread safe container?
There is some container containing pointers to custom class instances. Also, there is 1 thread (let's call it a modifier) that adds and removes elements of the container and N threads that bypass the elements and perform certain actions with them (let's call them handlers). The goal is to make the given container thread-safe and at the same time provide the modifier with priority access to the container. That is, if handlers in the amount of K pieces are waiting for access to the container and at this moment access requests a modifier, then you need to move the modifier to the head of the waiting queue and give it access first.
Answer the question
In order to leave comments, you need to log in
Have a look at the task queue library https://github.com/seanmiddleditch/jobxx/blob/deve...
Maybe this is what you need.
The main idea is that we do not block the queue for a long time, which means that the "modifier" can always put a new task there with almost no waiting.
By composition or inheritance, you make your container class with methods for getting and placing an object.
You make methods multi-threaded using Read Write Mutex.
Whether there are such mutexes in the standard library I do not know.
https://www.youtube.com/watch?v=KJS3ikoiLso
https://doc.qt.io/archives/qq/qq11-mutex.html#unde...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question