In gtk applications all execution is taking place inside the gtk_main function. And other graphical frame works have similar event loops like app.exec for QT and clutter_main for Clutter. However ZeroMQ is based on the assumption that there is an while (1) ... loop that it is inserted into (see for instance here for examples).
How do you combine those two execution strategies?
I am currently wanting to use zeromq in a clutter application written in C, so I would of course like direct answers to that, but please add answers for other variants as well.
It sounds like the ZeroMQ code wants simply to be executed over and over again as often as possible. The simplest way is to put the ZeroMQ code into an idle function or timeout function, and use non-blocking versions of the functions if they exist.
For Clutter, you would use
clutter_threads_add_idle()orclutter_threads_add_timeout(). For GTK, you would useg_idle_add()org_timeout_add().The more difficult, but possibly better, way is to create a separate thread for the ZeroMQ code using
g_thread_create(), and just use thewhile(1)construction with blocking functions as they suggest. If you do that, you will also have to find some way for the threads to communicate with each other – GLib’s mutexes and async queues usually do fine.