Threaded base loop for GTK and nanomsg

How do I write a main loop that blocks while waiting for messages from multiple sources? As I understand it, the preferred way to write an event loop is to block it while waiting for events.

However, how can you block blocking when messages can come from multiple sources?

I would like to write a GTK GUI that responds to both user input events and messages sent via nanomsg.

GTK allows you to handle events by gtk_main()

either calling or non-blocking with gtk_main_iteration_do (FALSE)

.

Nanomsg can receive messages in blocking or non-blocking mode, and polling for messages .

Is there some way to block until some source first gets an available "unblock"? That is, is there an alternative to use sleep

that remains sensitive to all events?

+3


source to share


1 answer


In your GTK + application, you can have as many threads as you want and you are not forced to use GMainLoop

instances). that any call that changes the UI happens in the main GTK + loop.

In this answer, I have provided an example with 100 threads updating the same interface.



In the end, you can fork and use whatever is more familiar to you in your thread (polling, blocking, or whatever), and only be careful when you need to notify (i.e. change the UI).

+3


source







All Articles