简体   繁体   English

同步线程和信令

[英]Synchronizing threads and signalling

I am trying to tell one thread that it's ok to continue with calculations after the other thread reads data from a named pipe. 我试图告诉一个线程在另一个线程从命名管道读取数据之后可以继续进行计算。 Currently, I have a while infinite loop which checks everytime for new data. 目前,我有一段时间的无限循环,每次都会检查新数据。 But this is inefficient as it consumes 100% of the CPU... 但这是低效的,因为它消耗了100%的CPU ...

My question is... Is there any way to wait until one thread has checked for new data and tell the other thread that it's ok to continue (something like a signal)? 我的问题是...有什么方法可以等到一个线程检查了新数据并告诉另一个线程可以继续执行(类似于信号)吗?

There are various solutions for your problem: 有多种解决方案来解决您的问题:

  • Signals and slots model of Qt Qt的信号和时隙模型
  • C++: Boost.Signals2 or Boost.Signals (deprecated) C ++:Boost.Signals2或Boost.Signals(已弃用)
  • C++: libsigc++ - template-based C ++:libsigc ++-基于模板
  • C++: sigslot C ++:sigslot
  • C++: XLObject - template-based, Qt-oriented. C ++:XLObject-基于模板,面向Qt。
  • C++: Signals C ++:信号
  • C: libevent - multi-threaded, platformindependent C:libevent-多线程,平台无关
  • C: libev - minimal alternative to libevent. C:libev-libevent的最小替代方案。

Have a look at them and find the one that fits the best for you. 看看它们,找到最适合您的一个。

Qt拥有您想要的一切,QThread可与信号和插槽配合使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM