Sharing a dataset among streams-C ++

I know that there are similar questions that I have already answered, but I ask this question because they definitely do not give what I would like to know. This applies to thread synchronization. The idea of ​​my project is that we receive data from a data collection card and plan and analyze data during data collection. So far I have a class for collecting data in one thread and a class for building on another thread. The data collection class stores data in the global ring buffer, and the plot class copies data from the global buffer and performs some processes for plotting (data point reduction, etc.). This is what I call the one (only) problem of the producer of the (one) consumer. I managed to complete this part using two semaphores that track,how many data points are stored by the collection class and how many of them are used by the construction class.

Now I would like to introduce another class into another thread that parses the data. Then I will have one producer and two consumers. I would like to impose the following conditions:

  • Two readers have the same dataset. Ie, each product made should be used by both readers, and not just one of them.
  • When the buffer is full, the data collection class overwrites the global buffer. When the reader loses data due to overwriting the data collection class buffer, this should be detected and, ideally, stored in a log (for example, what part of the data is skipped using readear (s)).
  • Calculation analysis class can be intense. For this, I may need a larger data buffer in the analysis class.

The way I dealt with the first part (the only producer and the only consumer) does not seem to apply to the case of the second part (one producer and two consumers) in a simple way. I wonder how I should act. I use C ++ with Qt for streaming, since I use Qt for the GUI. But the solution does not have to be with Qt. However, if possible, code examples or pseudo-codes will be greatly appreciated. I found a similar thread for my problem here ). It is suggested to use boost :: interprocess. However, since I had never used the Boost library before, and although I read the documents about boost :: interprocess, it looks too involved to understand myself.

Thank you so much!

Daisuke

+3

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


All Articles