asio 協程中 yield
(金慶的專欄 2017.12)
https://stackoverflow.com/questions/26127458/yielding-in-boost-asio-stackful-coroutine
Asio spawn() 可以產生一個協程,協程中可以調用 async_read(..., yield), async_write(..., yield), 但是不知道如何主動釋放控制權(yield)?
答案是:
iosvc.post(yield);
其他還可以是
iosvc.poll_one();
iosvc.poll();
應該是 post(yield) 最合適。
... polling the io_service avoids the context switch overhead, but unhandled exceptions from handlers will unwind and destroy the coroutine.
Powered by: C++博客 Copyright © 金慶