0

So I have been using boost as a solution for threading. I seem to be having an issue where the threads I create dont let the main thread that was executing them continue. Eg:

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 が実行を終了した後にのみ出力されます。メイン while(1) でも実行できるようにするにはどうすればよいですか? これができれば、明らかにスレッドの作成を while(1) の外に移動します:P 助けてくれてありがとう!

4

1 に答える 1

2

join作成したばかりのスレッドを呼び出さないでください。特に、終了joinするまでメインスレッドで待機します。ここを参照してください: http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_join.htmlspeech_thd

于 2013-05-16T04:23:03.453 に答える