jeudi 30 mai 2019

How to implement multhithread/task observer pattern?

I am working on a DAQ/instrumentation suite that should push large amounts of (double type) array data from/to HW devices e.g. DAQ boards or soundcards. Each HW device has a buffer, and will invoke callbacks when input buffer is full. The buffer should be pushed the buffer to several SW instruments e.g. oscillosope and spectrum analyzer. Each instrumennt as well as device driver should run in separate threads/tasks. My intention is to process about 1 Million doubles point per second.

For pushing data I have looked at IObservable/IObserver and I made an initial test which works without threads. The data type looks like this

public interface IAnalogInArrayData
{
        int NumberOfChannels { get; }
        int NumberOfPoints { get; }
        string[] XUnits { get; }
        string[] YUnits { get; }

        double[][] GetXData();
        double[][] GetXYata();
}


The double[][] could be up to [8][10000] and be updated every 100 msec.

Now I want to move to multi-threading (or tasks). I did some research and I am somewhat confused over the available alternatives:

  • according to an old SOF post (unfortunately I lost it), IObservable/IObserver should be replaced with Reactive extensions and Subject. However according to MSDN the Rx intro page is not updated anymore, but there is no suggestions to what should be used instead.
  • TPL: this seems to be a very high performing multithreading framework but I got lost in all options,

How can I make IObservable/IObserver thread safe? Should I skip threads and use tasks directly? Should I use Rx, TPL or am I missing any alternatives? What are the pros and cons of each approach? Feedback is greatly appreciated.

For pushing data I have looked at IObservable/IObserver and I made an initial test which works without threads, see attached code.

Aucun commentaire:

Enregistrer un commentaire