I have an object B
, composed of 10 double values. The double values are produced by a sensor which communicates via ethernet and sends out updates once every 1-2 milliseconds. Instances of B
must be used at 2 other places in the program to do some calculations and visualization.
In another thread, an object A
, holding ~1000 double values is updated every 4-10 milliseconds using another sensor.
Both objects have a time signature (procured by using boost::chrono::high_resolution_clock
when the sensor's update arrives)
Now I want to use two objects A
and B
that have been updated at nearly the same time to calculate some values for an object C
. This should be done while both threads are running, and the output used to do some visualization, computing averages, etc. The whole procedure is running for 1-2 hours and only instances of calculated C
s are used after that, instances of A
and B
are not longer needed.
What is the recommended method (or design pattern) to implement this communication and data sharing between the threads ?
At the moment, this whole construct is badly implemented, and the thread composing A
communicates directly with the one composing B
without using synchronization methods like mutexes.
- Should I use lockless double ended queues for storing
A
andB
s and read from this in the thread composingC
? - Should I use an (thread-safe) observer pattern like
boost::signals2
to "send" the instances ofA
andB
? - Or something different ?
Aucun commentaire:
Enregistrer un commentaire