asio 協(xié)程中 yield
(金慶的專欄 2017.12)
https://stackoverflow.com/questions/26127458/yielding-in-boost-asio-stackful-coroutine
Asio spawn() 可以產(chǎn)生一個(gè)協(xié)程,協(xié)程中可以調(diào)用 async_read(..., yield), async_write(..., yield), 但是不知道如何主動(dòng)釋放控制權(quán)(yield)?
答案是:
iosvc.post(yield);
其他還可以是
iosvc.poll_one();
iosvc.poll();
應(yīng)該是 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 © 金慶