0

I have two rather independent threads running. One generates data and one contains some display logic.

I transmit data via some

QMetaObject::invokeMethod(processor, "newData");

on the generator side. (processor is some QObject that is part of a Widget).

My data generation thread may be faster than the other one and everything gets pretty slow. Displaying old data is meaningless in my use case so i do not want that the invokeMethod calls queue up. Further invokes should be ignored or - at best - only the latest invoke should be executed.

How can I achieve this?

vlad_tepesch
  • 6,681
  • 1
  • 38
  • 80
  • 1
    It sounds as if you might want to invert things slightly. Currently you have the producer *pushing* data to the consumer regardless of whether or not the consumer is ready. Why not have the consumer *pull* the latest complete data from the producer as and when it's ready? – G.M. May 31 '18 at 14:03
  • The intuitive approach is to make it bidirectional messages, _sender_ receives a ready sync message from _receiver_ and transmits only thereafter – Mohammad Kanan May 31 '18 at 14:05
  • If you want to keep push/pull model then you can have signal that emits something like dataReady signal; in your consumer thread slot for this signal will just set internal isReady flag (e.g. of type std::atomic to avoid concurrency issues). Your consumer can then query the latest data from consumer whenever it's ready to consume next batch. – shrpq May 31 '18 at 16:00

1 Answers1

0

The newData method should do nothing but update the data record to be displayed, using a zero-cost-copy container (implicitly shared) and request a widget update. The widget update should then take the most recent data and display it.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313