GTK is not thread-safe, but thread-aware - it can be used from multiple thre开发者_如何学Goads ensuring that global lock is used to protect GTK API calls. If i need to post a message from worker thread to GTK GUI thread i just call gdk_threads_add_idle()
and specified callback will be called in GUI thread after some time.
But what is the easy way to do opposite thing - call specified callback from non-GUI
thread as user clicks a button?
Nothing prevents you from creating a new non-GUI loop with g_main_loop_new
, run it from your non-GUI thread with g_main_loop_run
and call g_idle_add
from your GUI thread when needed.
精彩评论