I have a multithreaded C application, where the main thread embeds a python runtime to realize a graphical user interface using Gtk4.
Another thread collects data, and, as I for obvious reasons can not directly call Gtk4 functions in another thread, I need some means to transport data between the threads and to signal to the main GUI thread that new data is available.
Transporting data is the easy part, the queue module handles this in a thread safe way. But how can I “signal” to the GUI thread that new data is available?
I want to somehow integrate this into the main loop of the Gtk4 GUI, in an efficient way. I know there is GLib.io_add_watch(), but I do not have a file descriptor on which to watch.
If I add a function to check the queue using GLib.add_idle(), this function get called way to often, making my CPU to go to full load.
What are your suggestions to signal to a running Gtk4 main loop that it should read data from a Queue that has been written to from another thread?