简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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