简体   繁体   English

从睡眠中唤醒主线程

[英]Wake up main thread from sleep

How can I wake up the main thread (currently sleeping because of a sleep() function call) from inside a child thread (without the child thread terminating)? 如何从子线程内部唤醒主线程(当前由于sleep()函数调用而进入睡眠状态)(子线程不终止)?

I want to make my main thread wait for a signal from a child thread without using an infinite loop or anything else that eats CPU power. 我想让我的主线程在不使用无限循环或其他消耗CPU能力的情况下等待子线程发出的信号。

The only things I found about this subject mentioned the main thread waking up a child thread but not the other way around. 我发现的关于该主题的唯一内容涉及主线程唤醒子线程,但没有相反的方法。

If all you want to do is pause the thread until it receives a signal from another thread, that's exactly what the pause function is for. 如果您要做的就是暂停线程,直到它从另一个线程接收到信号,这就是暂停功能的目的所在。

pause() causes the calling process (or thread) to sleep until a signal is delivered that either terminates the process or causes the invocation of a signal-catching function. pause()使调用进程(或线程)进入休眠状态,直到传递了终止该进程或导致调用信号捕获功能的信号为止。

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

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