Looks like I mistyped that code segments, there aren’t nested calls to
glib::idle_add, just one.
So let me give a little more detail on my program architecture. I have a background thread that acts as an interface to the serial port. It’s connected to my main thread by two
mpsc channels for bidirectional communication. It abstracts away the serial port, handles the near-real-time needs of interfacing with it, and it provides a higher-level API than the serial port library I’m using provides directly. So it works like “open serial port”, “send file to serial port”, “log incoming serial data to file”, etc.
Now my main program runs entirely within the GTK+ event loop. Sending commands to the serial thread is trivial as the serial thread is constantly looking for new events in the background on a 10ms timer. But for receiving events I have the background thread queue up a call to a
receiver function to run in the main thread after every message to process it. This prevents me needing some constant timer running to check for events.
So given that context, hopefully what I’m doing makes sense. I don’t want to ever pass the various program state across to the thread so it can feed it back into the callback, I want that data to stay strictly within the single main thread.