D
D
Dead_Bit2019-11-02 01:16:27
C++ / C#
Dead_Bit, 2019-11-02 01:16:27

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

2 answer(s)
T
tsarevfs, 2019-11-02
@tsarevfs

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.

T
tugo, 2019-11-02
@tugo

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 question

Ask a Question

731 491 924 answers to any question