我目前正在重新构思一个中等软件工程。 它包含一个由多个线条使用的类似核心内核的类。 目前, 此类使用 < code> Glib:: Dispatcher code > 来处理由多个线条释放的信号。 由于重构程序的一个目标是完全清除 < code> glibmm code > (因为 < code@ t code > 应用作新框架), 我正尝试用 < code> Boost code > 来找出如何“ 模拟” 调度器功能的方法。 我已经查看了 < code> Boost. Signals 和 < code> Boost.Signals2 , 但这两个图书馆似乎都没有为调度器提供替代方案。
为澄清调度员应做什么,请从中的“不跟随”:
Glib::Dispatcher works similar to sigc::signal. But unlike normal signals, the notification happens asynchronously through a pipe. This is a simple and efficient way of communicating between threads, and especially useful in a thread model with a single GUI thread.
No mutex locking is involved, apart from the operating system s internal I/O locking. That implies some usage rules:
- Only one thread may connect to the signal and receive notification, but multiple senders are allowed even without locking.
- The GLib main loop must run in the receiving thread (this will be the GUI thread usually).
- The Dispatcher object must be instantiated by the receiver thread.
- The Dispatcher object should be instantiated before creating any of the sender threads, if you want to avoid extra locking.
- The Dispatcher object must be deleted by the receiver thread.
- All Dispatcher objects instantiated by the same receiver thread must use the same main context.
您能否给我一些正确方向的指针? 这是使用 Boost.Signals
或 boost.Signals2
实现的功能吗?
编辑: 正如一位评论家正确指出的, 使用 < codet 也许是个选项。 但是, 我所重订的类别非常低, 我不想添加此额外依赖性 。