Single queue for multiple manufacturers

I am new to multithreading and developed a program that receives data from two microcontrollers that measure different temperatures (Ambient and Water) and displays the data on the screen. The program is single-threaded right now and its performance is SUCKS A BIG ONE.

I get basic design approaches with multithreading, but not enough to create a thread to complete the task, but what I don't get is how to get the threads to perform a separate task and put the data in a common data pool. I decided that I needed to create a queue in which there is one consumer and several manufacturers (I would like to use std :: queue). I saw some code in the gtkmm thread documents that show one Con / Pro queue, and they would block the queue object, producing data, and signal that it had finished the sleeping thread, after which the producer would sleep. Why would I need to sleep a stream, there would be data conflicts if I did not sleep any of the streams, and the stream would sleep, causing data attenuation, a significant delay (I need real-time data to be 30 frames sec)

How would I start coding such a queue using the gtkmm / glibmm library.

+4
source share
2 answers

Here is a suggestion:
1. Have two streams that are responsible for receiving data and placing in the buffer. Each thread has its own (circular) buffer.
2. There will be a third stream, which is responsible for receiving data from buffers and displaying it on the screen.
3. The screen stream sends messages to data streams, requesting some data, and then displays the data. Messages help synchronize execution and avoid blocking.
4. None of the threads should "wait on one or more objects", but interrogate events.

Think of this scenario using people. One person gives readings of water temperature. Another person providing ambient temperature readings. A third person receives or requests data and displays the data (on a white board). The goal is to ensure maximum efficiency for all users without any collisions.

+2
source

If you are looking for a blocking opportunity, you will not find it. When data structures are written, it is necessary that the two streams simultaneously update the data structure and distort it.

Is there any reason why you cannot have every thread going on it with its own structure and then combine the results at the end?

+2
source

Source: https://habr.com/ru/post/1308260/


All Articles