简体   繁体   English

std::this_thread::sleep_for() 无限睡眠

[英]std::this_thread::sleep_for() sleep infinite

So I have the main thread communicating with other threads, and at some point I want the sub threads to sleep one at a time, but when I use the sleep_for method and put in 2 seconds it never stop sleeps, but with valgrind it does stop sleep, without, it dont work.所以我让主线程与其他线程通信,并且在某些时候我希望子线程一次睡一个,但是当我使用sleep_for方法并输入 2 秒时它永远不会停止睡眠,但是使用 valgrind 它确实会停止睡觉,没有,它不起作用。 Here's my code:这是我的代码:


            int cookTime = (int)_currPizza->getCookTime() * this->_multiplier;
            printf("cook time %d\n", cookTime);
            // cookTime is 2;
            printf("start cooking\n");
            std::this_thread::sleep_for(std::chrono::seconds(cookTime));
            printf("end cooking\n");

If you want to wait for finishing the job of created thread you should call thread.join() in creator thread.如果您想等待完成创建线程的工作,您应该在创建者线程中调用 thread.join()。

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

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