[英]Blocking thread for wait queue
I have applications with 2 threads. 我有2个线程的应用程序。 In first (main) thread I want to generate some message and send it to second thread. 在第一个(主)线程中,我想生成一些消息并将其发送到第二个线程。 Is there method to blocked thread for wait incoming message (like a queue in embended OS(FreeRTOS, TNKernel etc))? 是否有方法来阻止线程等待传入的消息(例如嵌入式OS(FreeRTOS,TNKernel等)中的队列)?
while (true) {
waitQueue(TIMEOUT_INFINITY);
}
in waitQueue(TIMEOUT_INFINITY);
在waitQueue(TIMEOUT_INFINITY);
current thread becomes blocked, when in main thread generates some message waitQueue
releases thread. 当前线程在主线waitQueue
某些消息时被阻塞, waitQueue
释放线程。
The natural way for doing this in Qt is calling QThread::exec()
in the thread (which is what the default implementation for QThread::run()
do). 在Qt中执行此操作的自然方法是在线程中调用QThread::exec()
(这是QThread::run()
的默认实现)。
after that to execute a QObject
instance (worker object)'s slots in that thread, you can set the instance's affinity to the new thread using QObject::moveToThread()
, then when a signal connected to some slot in that instance is emitted, the slot will be invoked in the new thread. 之后,要在该线程中执行QObject
实例(工作对象)的插槽,可以使用QObject::moveToThread()
将实例的亲和力设置为新线程,然后在连接到该实例中某个插槽的信号发出时,该插槽将在新线程中调用。
Instantiating a QThread provides a parallel event loop, allowing QObject slots to be invoked in a secondary thread. 实例化QThread提供了一个并行事件循环,从而允许在辅助线程中调用QObject插槽。 Subclassing a QThread allows the application to initialize the new thread before starting its event loop, or to run parallel code without an event loop. 子类化QThread允许应用程序在开始其事件循环之前初始化新线程,或者在没有事件循环的情况下运行并行代码。
see QThread class , QObject class , Threads and QObject , along with Qt event loops . 请参阅QThread类 , QObject类 , Threads和QObject ,以及Qt事件循环 。
Hope this helps. 希望这可以帮助。 . 。 . 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.