0

所以我一直在使用 boost 作为线程的解决方案。我似乎有一个问题,我创建的线程不允许执行它们的主线程继续。例如:

int main(){
    while(1){
        speech listen; //create speech object
        boost::thread speech_thd(boost::bind(&speech::Run,&listen));
        speech_thd.join();
        std::cout<<"test\n";
        //Some sleep call here 
    }

“测试”调用仅在 Speech_thd 完成执行后打印。我将如何创建它以便我也可以在 main while(1) 上执行?如果我能做到这一点,我显然会将线程创建移到 while(1) 之外:P 感谢您的帮助!

4

1 回答 1

2

不要调用join您刚刚创建的线程 -join特别是在主线程中等待直到speech_thd终止,请参见此处: http: //pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_join.html

于 2013-05-16T04:23:03.453 回答