- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以基本上我正在编写以下步骤来创建基于 dbus 的应用程序。1. g_bus_watch_name(特定服务出现的回调)2. g_signal_connect 附加到服务提供的某些信号。 g_signal_connect(代理,"xyz", G_CALLBACK(回调), NULL);
我希望“回调”在特定线程上下文下运行。
任何提示将不胜感激
最佳答案
来自the GDBusProxy
documentation :
A GDBusProxy instance can be used from multiple threads but note that all signals (e.g. “g-signal”, “g-properties-changed” and “notify”) are emitted in the thread-default main context of the thread where the instance was constructed.
因此请确保 GMainContext
您希望在创建 GDBusProxy
时以线程默认方式发出信号。典型的模式是调用 g_main_context_push_thread_default()
在线程函数的开始处,然后创建 GDBusProxy 并将信号连接到它,并将对象完全保留在该线程内。
有关使用 GMainContext
的推荐模式的更多信息,请参阅 the tutorial 。特别是,它建议每个线程(该线程的默认值)有一个 GMainContext
,并且不要在线程之间移动它们。虽然受支持,但在线程之间移动上下文的速度很慢(由于锁定),并且使得其余代码的控制流和线程安全性很难推理。
关于glib - 如何将 glib 信号回调附加到特定线程上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50020800/
我是一名优秀的程序员,十分优秀!