I'm working with on real-time application divided in two parts (threads):
- processing
- graphics
the output of processing is an array of fixed size (of float) and to maintain a real-time performance I want to send such data to another thread that will draw, for example graphs, at its own pace.
I've looked into atomic and lock but I can't figure out how to make the application thread-safe given that the two processes are completely independent.
Sample code:
class A {
float data[n];
processData() {
data = ... ;
}
}
class B {
void draw() {
// requires data[] from class A
}
}
Both classes are initialized in the main thread and I've tried to define a float* pointer there and pass it to the other two threads, processing assigns it to data[] and graphics is able to read it but there's obviously errors when one is reading and the other is modifying it at the same time.
Aucun commentaire:
Enregistrer un commentaire