开发者

GTK / Glib: how to post message from GUI thread to worker thread?

开发者 https://www.devze.com 2023-04-05 03:44 出处:网络
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 threa

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号