简体   繁体   English

我如何让子线程在某种情况下等待并被父线程的一次调用唤醒?

[英]How I get child threads wait on a condition and all waked up by one call from parent thread?

子线程进入睡眠状态,父线程可以调用某些例程来唤醒所有子线程来运行吗?

If you're using POSIX threads (pthreads), then pthread_cond_wait and (in your case) pthread_cond_broadcast are your friends. 如果您使用的是POSIX线程(pthread),那么pthread_cond_wait和(在您的情况下) pthread_cond_broadcast是您的朋友。 :-) :-)

If you are using Win32, then you can use a manual-reset Event . 如果使用的是Win32,则可以使用手动重置的Event Your parent thread would call SetEvent() and could wake up all child threads waiting for that object with a function such as WaitForSingleObject() . 您的父线程将调用SetEvent()并可以使用诸如WaitForSingleObject()类的功能唤醒所有等待该对象的子线程。

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

相关问题 如何让主线程等待所有子线程完成? - How to make main thread wait for all child threads finish? 如何从父线程中杀死子线程 - C - How to Kill child threads from Parent thread - C Linux:是否从一个线程调用wait()会导致所有其他线程也进入睡眠状态? - Linux: Whether calling wait() from one thread will cause all other threads also to go to sleep? 系统调用如何让父母等待孩子 - System call how to make parent wait for child C - 如何在其中一个线程用条件变量向主线程发出信号后终止所有线程? - C - How to terminate all threads after one of them signals the main thread with a condition variable? C中等待父线程输入时如何创建子线程和阻塞 - How to create Child Threads and block while waiting for input from the Parent thread in C 如何让一个线程等待来自不同线程的多个条件信号? - How to make a thread wait for multiple conditional signals from different threads? 如何让父进程等待所有子进程完成? - How to make parent wait for all child processes to finish? 父进程如何通过等待调用_exit的子进程获得终止状态 - How does parent process get the termination status through wait from a child process which calls _exit 等待所有子线程完成(在C中) - Wait for all child thread to finish (in C)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM