gpt4 book ai didi

c++ - deadline_timer::wait 是否屈服于其他任务?

转载 作者:行者123 更新时间:2023-11-28 04:49:50 25 4
gpt4 key购买 nike

调用 deadline_timer::wait 是否会导致 io_service 中的其他任务在等待时执行,或者如果在其中调用它是否会完全阻塞 io 线程?

io_service service;
io_service::work work(service);
thread thread([&] { service.run() });

service.post([&]
{
deadline_timer timer(service, posix_time::seconds(100000);
timer.wait();
});

service.post([&]
{
std::cout << "HELLO!";
}):

thread.join();

应该打印 hello 吗?

最佳答案

不,它不会,它会在那个时候阻塞。 qoute :

This function is used to wait for the timer to expire. This function blocks and does not return until the timer has expired.

自己看example .

关于c++ - deadline_timer::wait 是否屈服于其他任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48463558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com