P
P
pixik2015-07-09 12:09:54
C++ / C#
pixik, 2015-07-09 12:09:54

How to implement the architecture of a multi-threaded application for drawing a graph?

Good time, dear developers!
I came across a problem and something tells me that there must be some pattern here, because the problem is quite typical.
Essence:
There is a data source that generates a stream at a speed of 5 Gb / s (USB 3.0).
The project is written in C++ using STL, QWT, QT libraries.
You need to process this stream in the application in a certain way (ie, perform some not very heavy math) or write the stream to disk as a binary file.
I have no experience in solving such problems, so I solved it as I imagined.
After some thought, I decided to do this:
There are 3 threads and a shared non-blocking queue

  1. A thread that receives data from USB and puts the data in a queue
  2. A thread that scans the queue for objects in an endless loop. If the queue has objects,
    then the thread gets them from the queue and sends them for further processing (either writes to a file, or somehow processes and displays them on the chart)
  3. GUI thread that draws graphics and handles user interaction

Can you please let me know if there is a standard way to solve this problem? Why is my decision bad? If you advise literature in this area, I will be very grateful =)
Thank you all for your participation!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Martyanov, 2015-07-09
@vilgeforce

Your solution is bad right off the bat only because the second stream "outputs" the data on the chart. Pulling gui from a side stream is a bad idea, there will be strange and elusive bugs with high chances. And so everything is OK, in my opinion.

D
DancingOnWater, 2015-07-09
@DancingOnWater

Moment number 1. Qt requires that the GUI only live in the main thread. And if the math is simple, and the USB speed is not critical, then let the math lie in the same stream. as reading from USB.
Moment number 2. An infinitely spinning cycle is the last measure. In Qt you have signals, so use them.
USb receives data and pushes the signal. it is picked up by mathematics and, after processing, pushes the signal. It is received by the GUI and displays the data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question