GTK 3个线程管理 [英] GTK 3 Threads management

查看:355
本文介绍了GTK 3个线程管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,在我们需要使用gdk_threads_enter和gdk_threads_leave,但现在这个功能是去precated,我感到困惑的线程。

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.

我应该只是增加线程与g_idle_add,这就是它?

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

推荐答案

有关工作人员是无关的UI的东西,使用 GThread API,任何东西UI相关的你有无的使用 g_idle_add / g_timeout_add 或附加一个自定义的 GSource 到所需的事件循环。
在某些情况下,你想结合的 - 做一些工作在 GThread 并通知用户界面从那里 - 只要劳动者完成 - 通过 g_idle_add

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.

如果您正在开发一个库,你也可以实现它通过一个非常干净和取消的方式 GAsyncInitableIface (尽管这需要更多的阅读开始真正实施之前,它)。

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).

在回应@ ptomato的评论:

In response to @ptomato's comment:

您应该使用gdk_threads_add_idle()和gdk_threads_add_timeout()
  而不是g_idle_add()和g_timeout_add(),因为没有根据库
  你的控制可能会使用pcated GDK去$ P $锁定机制。如果
  你确信没有code在您的应用程序和库
  使用德precated gdk_threads_enter()或gdk_threads_leave()方法
  那么你可以放心地使用g_idle_add()和g_timeout_add()。

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().

这篇关于GTK 3个线程管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆