I have the following struct
struct info {
unsigned long a;
unsigned long b;
};
atomic <info> data;
used by a writer thread and a reader thread. The reader has to respond to the new values as fast as possible. To do that I’ve implemented the following in the reader :
while (true) {
auto value = data.load();
// do some operations given these new values
}
This operation is very processor intensive. I’ve opted for this method because I believe it’s faster than, for example, using a condition variable and then waiting for the reader thread to be awakened when data changes. Also, the data updates quite frequently, hundreds of times per second. Is there a better way to do this while still having the fastest reaction time?
Aucun commentaire:
Enregistrer un commentaire