# coroutine **Repository Path**: niukey/coroutine ## Basic Information - **Project Name**: coroutine - **Description**: C++ 11 协程 - **Primary Language**: C++ - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2016-04-29 - **Last Updated**: 2021-06-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #coroutine #C++ 11 协程 ### 支持多线程调度 ### 支持协程之间发生消息 chan 类似 go 语音的channal ### 支持协程 yield, sleep, mutex, condition_variable ### 支持async future 调度池 ###------------------------------------------------------------------------------------------------------ ``` include "scheduler_pool.h" std::string func(int a) { std::cout << a << std::endl; this_fiber->sleep_for(std::chrono::milliseconds(2000)); std::cout << a <<"endl" << std::endl; return "result come from a future ,cool!"; } int main() { bool is_done = false; scheduler s; scheduler_pool::get_instance() .init() .auto_houseclean(2000) .get_scheduler()->append_fiber([] { do { this_fiber->sleep_for(std::chrono::seconds(1)); std::cout << "kick." << std::endl; } while (1); }); s.append_fiber([&] { auto f = scheduler_pool::async(func, 2); assert(f.valid() == false); f.wait(); assert(f.valid() == true); auto result = f.get(); std::cout << result << std::endl; is_done = true; }); s.start(); getchar(); } ``` ###------------------------------------------------------------------------------------------------------ ###------------- ###下一步开发 网络IO