我可以在C ++中阻止线程及其子级吗?>

问题描述 投票:0回答:1

我有这样的代码

Create thread_1 and bind task 1 to that;
Create thread_2 and bind task 2 to that;
Create thread_3 and it monitors the keyboards and work as follow:
     while(true){
       get the next key;
       if (the next key == 'p')
            pause_the_code();
       if (the next key == 'r')
            resume_the_code();
       if(the next key == 'q'
            exit the while loop
      }
// can I here block the Thread_1 and _Thread_2 with all of their children 
//with wait() when I call pause_the_code(); or notify them when I call resume_the_code();

请注意,hread_1和Thread_2可以动态创建不同的线程。

我有这样的代码创建线程_1并将任务1绑定到该代码;创建thread_2并将任务2绑定到该线程;创建thread_3并监视键盘并按以下方式工作:while(true){...

multithreading c++11 concurrency c++14 boost-asio
1个回答
0
投票

否,您无法从一个线程伸出手来暂停或阻止另一个线程。并非以任何安全的方式。

© www.soinside.com 2019 - 2024. All rights reserved.