开发者

C++/CLI efficient multithreaded circular buffer

开发者 https://www.devze.com 2022-12-13 21:45 出处:网络
I have four threads in a C++/CLI GUI I\'m developing: Collects raw data The GUI itself A background processing thread which takes chunks of raw data and produces useful information

I have four threads in a C++/CLI GUI I'm developing:

  1. Collects raw data
  2. The GUI itself
  3. A background processing thread which takes chunks of raw data and produces useful information
  4. Acts as a controller which joins the other three threads

I've got the raw data collector working and posting results to the controller, but the next step is to store all of those results so that the GUI and background processor have access to them.

New raw data is fed in one result at a time at regular (frequent) intervals. The GUI will access each new item as it arrives (the controller announces new data and the GUI then accesses the shared buffer). The data processor will periodically read a chunk of the buffer (a seconds worth for example) and produce a new result. So effectively, there's one producer and two consumers which need access.

I'v开发者_运维百科e hunted around, but none of the CLI-supplied stuff sounds all that useful, so I'm considering rolling my own. A shared circular buffer which allows write-locks for the collector and read locks for the gui and data processor. This will allow multiple threads to read the data as long as those sections of the buffer are not being written to.

So my question is: Are there any simple solutions in the .net libraries which could achieve this? Am I mad for considering rolling my own? Is there a better way of doing this?


Is it possible to rephrase the problem so that:

  1. The Collector collects a new data point ...
  2. ... which it passes to the Controller.
  3. The Controller fires a GUI "NewDataPointEvent" ...
  4. ... and stores the data point in an array.
  5. If the array is full (or otherwise ready for processing), the Controller sends the array to the Processor ...
  6. ... and starts a new array.

If the values passed between threads are not modified after they are shared, this might save you from needing the custom thread-safe collection class, and reduce the amount of locking required.

0

精彩评论

暂无评论...
验证码 换一张
取 消