GTK 3 Threads management

若如初见. 提交于 2019-12-24 08:26:35

问题


I know that before we needed to use gdk_threads_enter and gdk_threads_leave but now this functions are deprecated and I'm confused about threads.

Should i just add threads with g_idle_add and that's it?


回答1:


For workers that are unrelated to UI stuff, use the GThread API, for anything UI related you have to use g_idle_add/g_timeout_add or attach a custom GSource to the desired event loop. In some cases you'd want to combine those - do some work in a GThread and notify the UI from there - as soon as the worker has finished - via g_idle_add.

If you are developing a library you could also implement it in a very clean and cancelable manner via the GAsyncInitableIface (though that requires a bit more reading before starting to actually implement it).


In response to @ptomato's comment:

You should use gdk_threads_add_idle() and gdk_threads_add_timeout() instead of g_idle_add() and g_timeout_add() since libraries not under your control might be using the deprecated GDK locking mechanism. If you are sure that none of the code in your application and libraries use the deprecated gdk_threads_enter() or gdk_threads_leave() methods, then you can safely use g_idle_add() and g_timeout_add().




回答2:


Use g_thread_new (name, func, data)



来源:https://stackoverflow.com/questions/24820507/gtk-3-threads-management

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!