S
S
samokiller2021-01-04 19:46:41
Qt
samokiller, 2021-01-04 19:46:41

How to organize QSharedMemory into 3 threads?

I write in qt. The goal is speed. The size of the consumed memory is not particularly important.

The 1st process is a library that connects to a third-party application, receives a data stream from it and places them in SharedMemory.
The 2nd process contains 2 threads, one thread reads the SharedMemory data, selects the necessary ones and processes them, the second thread reads the SharedMemory and saves the data to the database.

After both threads have read the data, they must apparently somehow send a signal to the 1st process, and then the first one can clear the data and write the next portion.
And so in a circle.

1) Is this architecture optimal for performance?
2) What is the best way to organize a signal to the 1st process that both threads have taken the data and it is possible to clear and write new ones? Do I need to use mutexes/semaphores for this? Or just trying to capture memory? It seems to me that the best option would be to write the status to some kind of buffer, ala 0 - the data has been read, it can be overwritten, 1 - the data has been taken by the first stream, 2 - the data has been taken by the second stream. What tools are used to implement such a mechanism?
3) The slowest link in this chain is the thread that writes to the database. Whether it is possible, at preservation of one buffer of SharedMemory, to make so that calculations in the first flow did not wait for a delay while the data is thrown off in a DB?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacob E, 2021-01-04
@Zifix

1) Should work as quickly as possible, in theory.
2) Yes, you need to use it, read something about synchronization primitives, how they work and how they are used in classical tasks.
Very roughly speaking, the second process should hang on the semaphore captured by the first while it writes data to SM. After that, the first process must hang on the semaphore captured by the second one, until the second thread reads the data.
3) Why does he need to know what the second thread is doing there? I read the data, and immediately began to do the calculations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question