{"id":334839,"date":"2022-06-22T15:00:32","date_gmt":"2022-06-22T15:00:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=334839"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=334839","title":{"rendered":"<span>C++20: \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b cppcoro<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d5d\/b21\/392\/d5db21392613c154cb755fdec5942104.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d5d\/b21\/392\/d5db21392613c154cb755fdec5942104.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 cppcoro \u043e\u0442 \u041b\u044c\u044e\u0438\u0441\u0430 \u0411\u0435\u0439\u043a\u0435\u0440\u0430 (Lewis Baker) \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0442\u043e, \u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0430\u0435\u0442 \u043d\u0430\u043c C++20 \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d C++, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043d\u0430 Coroutines TS.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8d0\/169\/a6a\/8d0169a6aba33d32800aa35609c63483.png\" width=\"602\" height=\"216\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8d0\/169\/a6a\/8d0169a6aba33d32800aa35609c63483.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0434\u0432\u0430 \u043c\u043e\u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u043f\u043e\u0441\u0442\u0430 &#171;<a href=\"https:\/\/bit.ly\/InfiniteDataStream\">C++20: \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438<\/a>&#187; \u0438 &#171;<a href=\"https:\/\/bit.ly\/ThreadSynchronizationCoroutines\">C++20: \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d<\/a>&#187; \u0431\u044b\u043b\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u041d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u0441\u0442\u044b \u043f\u0440\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043b\u0435\u0433\u0447\u0435 \u0443\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c\u0441\u044f. \u042f \u0449\u0435\u0434\u0440\u043e \u0441\u043d\u0430\u0431\u0434\u0438\u043b \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d <a href=\"https:\/\/github.com\/lewissbaker\/cppcoro\">cppcoro<\/a>.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u044f \u0445\u043e\u0447\u0443 \u043d\u0430\u0447\u0430\u0442\u044c \u0441 \u043f\u0430\u0440\u044b \u0441\u043b\u043e\u0432 \u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445 \u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d.<\/p>\n<h3>cppcoro<\/h3>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 cppcoro \u043e\u0442 \u041b\u044c\u044e\u0438\u0441\u0430 \u0411\u0435\u0439\u043a\u0435\u0440\u0430 \u0431\u0435\u0440\u0435\u0442 \u0437\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 Coroutine TS. TS \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a <em>technical specifications<\/em> (\u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438) \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432 C++20. \u041b\u044c\u044e\u0438\u0441 \u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 cppcoro \u0441 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 Coroutines TS \u043d\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432 C++20.<\/p>\n<p>\u042f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u043f\u0440\u0438\u0447\u0438\u043d\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e: <strong>\u0432 C++20 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0435 \u0441\u0430\u043c\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043a\u043e\u0440\u0443\u0442\u0438\u043d.<\/strong> \u042d\u0442\u043e\u0442 \u043d\u044e\u0430\u043d\u0441 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432 C++20, \u0442\u043e \u0432\u044b \u0441\u0430\u043c\u0438 \u043f\u043e \u0441\u0435\u0431\u0435. \u0412\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d C++20. \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u0430\u043a\u0438\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0432 C++23. \u0427\u0435\u0441\u0442\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u044f \u0441\u0447\u0438\u0442\u0430\u044e \u044d\u0442\u043e \u0447\u0440\u0435\u0437\u0432\u044b\u0447\u0430\u0439\u043d\u043e \u0432\u0430\u0436\u043d\u044b\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u0430 \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0431\u0435\u043b \u2014 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442 cppcoro. \u041e\u043d\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d, awaitable \u0442\u0438\u043f\u044b, \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043e\u0442\u043c\u0435\u043d\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (cancellation), \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0438, \u043d\u0435\u0442\u0432\u043e\u0440\u043a\u0438\u043d\u0433, \u043c\u0435\u0442\u0430\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u043e\u0432.<\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 cppcoro<\/h2>\n<p>\u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f cppcoro \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 Coroutines TS \u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 Windows (Visual Studio 2017) \u0438\u043b\u0438 Linux (Clang 5.0\/6.0 \u0438 libc++). \u0414\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432 \u043d\u0430\u0448\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u0445 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e3d\/1c6\/80b\/e3d1c680b01b833bf04b742804109c1e.png\" width=\"602\" height=\"76\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e3d\/1c6\/80b\/e3d1c680b01b833bf04b742804109c1e.png\"\/><figcaption><\/figcaption><\/figure>\n<ul>\n<li>\n<p><code>-std=c++17<\/code>: \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 C++17<\/p>\n<\/li>\n<li>\n<p><code>-fcoroutines-ts<\/code>: \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 Coroutines TS C++<\/p>\n<\/li>\n<li>\n<p><code>-Iinclude<\/code>: \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 cppcoro\u00a0<\/p>\n<\/li>\n<li>\n<p><code>-stdlib=libc++<\/code>: <a href=\"https:\/\/en.wikipedia.org\/wiki\/LLVM\">LLVM<\/a> \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/p>\n<\/li>\n<li>\n<p><code>libcppcoro.a<\/code>: \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 cppcoro<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b \u0440\u0430\u043d\u0435\u0435: \u043a\u043e\u0433\u0434\u0430 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c cppcoro \u0431\u0443\u0434\u0435\u0442 \u0430\u043a\u0442\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0434\u043e C++20, \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u043c C++20. \u0410 \u0441\u0435\u0439\u0447\u0430\u0441 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 C++23.<\/p>\n<p>cppcoro \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432 \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u0438, \u0438 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0444\u0438\u0447\u0438 cppcoro, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u0440\u0443\u0442\u0438\u043d.<\/p>\n<h2>\u0422\u0438\u043f\u044b \u043a\u043e\u0440\u0443\u0442\u0438\u043d<\/h2>\n<p>cppcoro \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0438\u0434\u044b \u0437\u0430\u0434\u0430\u0447 (task) \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 (generator).\u00a0<\/p>\n<h3>task&lt;T><\/h3>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0437\u0430\u0434\u0430\u0447\u0430? \u0412\u043e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u0432\u0437\u044f\u0442\u043e\u0435 \u043f\u0440\u044f\u043c\u0438\u043a\u043e\u043c \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430 (task) <\/strong>\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043b\u0435\u043d\u0438\u0432\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043d\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 (awaited).<\/p>\n<\/li>\n<\/ul>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u2014 \u044d\u0442\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>main<\/code> \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>first<\/code>, <code>first<\/code> \u043e\u0436\u0438\u0434\u0430\u0435\u0442 <code>second<\/code>, \u0430 <code>second<\/code> \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0442\u0440\u0435\u0442\u044c\u044e.<\/p>\n<pre><code class=\"cpp\">\/\/ cppcoroTask.cpp  #include &lt;chrono> #include &lt;iostream> #include &lt;string> #include &lt;thread>  #include &lt;cppcoro\/sync_wait.hpp> #include &lt;cppcoro\/task.hpp>  using std::chrono::high_resolution_clock; using std::chrono::time_point; using std::chrono::duration;  using namespace std::chrono_literals; \/\/ 1s     auto getTimeSince(const time_point&lt;high_resolution_clock>&amp; start) {          auto end = high_resolution_clock::now();     duration&lt;double> elapsed = end - start;     return elapsed.count();      }  cppcoro::task&lt;> third(const time_point&lt;high_resolution_clock>&amp; start) {          std::this_thread::sleep_for(1s);     std::cout &lt;&lt; \"Third waited \" &lt;&lt; getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;      co_return;                                                     \/\/ (4)          }  cppcoro::task&lt;> second(const time_point&lt;high_resolution_clock>&amp; start) {          auto thi = third(start);                                       \/\/ (2)     std::this_thread::sleep_for(1s);     co_await thi;                                                  \/\/ (3)          std::cout &lt;&lt; \"Second waited \" &lt;&lt;  getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;      }  cppcoro::task&lt;> first(const time_point&lt;high_resolution_clock>&amp; start) {          auto sec = second(start);                                       \/\/ (2)     std::this_thread::sleep_for(1s);     co_await sec;                                                   \/\/ (3)          std::cout &lt;&lt; \"First waited \" &lt;&lt;  getTimeSince(start)  &lt;&lt; \" seconds.\" &lt;&lt; std::endl;      }  int main() {          std::cout &lt;&lt; std::endl;          auto start = high_resolution_clock::now();     cppcoro::sync_wait(first(start));                              \/\/ (1)          std::cout &lt;&lt; \"Main waited \" &lt;&lt;  getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;          std::cout &lt;&lt; std::endl;  }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c, \u044d\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043e\u0441\u043e\u0431\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u0440\u0430\u0431\u044b \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>main<\/code> \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439. <code>cppcoro::sync_wait<\/code> (\u0441\u0442\u0440\u043e\u043a\u0430 (1)) \u0447\u0430\u0441\u0442\u043e \u0441\u043b\u0443\u0436\u0438\u0442 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 (\u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430). \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>first<\/code>, \u043a\u0430\u043a \u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>start<\/code> (\u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u044b) \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u044d\u0442\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435? \u041e\u043d\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443 <code>second<\/code> (\u0441\u0442\u0440\u043e\u043a\u0430 (2)), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0437\u0430\u0441\u044b\u043f\u0430\u0435\u0442 \u043d\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430 <code>sec<\/code> \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 (3). \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>second<\/code> \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441 <code>third<\/code>, \u043d\u043e \u0443 <code>third<\/code> \u0443\u0436\u0435 \u0434\u0440\u0443\u0433\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435. <code>third<\/code> \u2014 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438 \u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0434\u0440\u0443\u0433\u0443\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443. \u041a\u043e\u0433\u0434\u0430 <code>third<\/code> \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043f\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u0440\u0430\u0431\u043e\u0442\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u043e \u0442\u0440\u0438 \u0441\u0435\u043a\u0443\u043d\u0434\u044b.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c66\/6ea\/776\/c666ea7764442c30e7dc0ac5a1d88d85.png\" width=\"351\" height=\"228\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c66\/6ea\/776\/c666ea7764442c30e7dc0ac5a1d88d85.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0431\u0443\u0434\u0443\u0442 \u0431\u0443\u0434\u0443\u0442 \u0443\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0441\u043e\u043d \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 <code>co_await<\/code>?<\/p>\n<pre><code class=\"cpp\">\/\/ cppcoroTask2.cpp  #include &lt;chrono> #include &lt;iostream> #include &lt;string> #include &lt;thread>  #include &lt;cppcoro\/sync_wait.hpp> #include &lt;cppcoro\/task.hpp>  using std::chrono::high_resolution_clock; using std::chrono::time_point; using std::chrono::duration;  using namespace std::chrono_literals;  auto getTimeSince(const time_point&lt;::high_resolution_clock>&amp; start) {          auto end = high_resolution_clock::now();     duration&lt;double> elapsed = end - start;     return elapsed.count();      }  cppcoro::task&lt;> third(const time_point&lt;high_resolution_clock>&amp; start) {          std::cout &lt;&lt; \"Third waited \" &lt;&lt; getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;     std::this_thread::sleep_for(1s);     co_return;          }   cppcoro::task&lt;> second(const time_point&lt;high_resolution_clock>&amp; start) {          auto thi = third(start);     co_await thi;          std::cout &lt;&lt; \"Second waited \" &lt;&lt;  getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;     std::this_thread::sleep_for(1s);      }  cppcoro::task&lt;> first(const time_point&lt;high_resolution_clock>&amp; start) {          auto sec = second(start);     co_await sec;          std::cout &lt;&lt; \"First waited \" &lt;&lt;  getTimeSince(start)  &lt;&lt; \" seconds.\" &lt;&lt; std::endl;     std::this_thread::sleep_for(1s);      }  int main() {          std::cout &lt;&lt; std::endl;       auto start = ::high_resolution_clock::now();          cppcoro::sync_wait(first(start));          std::cout &lt;&lt; \"Main waited \" &lt;&lt;  getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;          std::cout &lt;&lt; std::endl;  }<\/code><\/pre>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u0443\u0436\u0435 \u0438 \u0441\u0430\u043c\u0438 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>main<\/code> \u0436\u0434\u0435\u0442 \u0442\u0440\u0438 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0441\u0435\u043a\u0443\u043d\u0434\u0443.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a53\/99d\/59d\/a5399d59d28d263fdbe677a70b15791b.png\" width=\"351\" height=\"228\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a53\/99d\/59d\/a5399d59d28d263fdbe677a70b15791b.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u043f\u043e\u0441\u0442\u0430\u0445 \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 (threads) \u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u0430\u043c\u0438 (signals).\u00a0\u00a0<\/p>\n<h3>generator<\/h3>\n<p>\u0412\u043e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0442 cppcoro:<\/p>\n<ul>\n<li>\n<p><code>generator<\/code> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0438\u043f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0442\u0438\u043f\u0430 <code>T<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043b\u0435\u043d\u0438\u0432\u043e \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u0432\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0439 \u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 <code>cppcoroGenerator.cpp<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0434\u0432\u0443\u0445 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">\/\/ cppcoroGenerator.cpp  #include &lt;iostream> #include &lt;cppcoro\/generator.hpp>  cppcoro::generator&lt;char> hello() {     co_yield 'h';                       co_yield 'e';                        co_yield 'l';                        co_yield 'l';                        co_yield 'o';                    }  cppcoro::generator&lt;const long long> fibonacci() {     long long a = 0;     long long b = 1;     while (true) {         co_yield b;                 \/\/ (2)         auto tmp = a;         a = b;         b += tmp;     } }  int main() {      std::cout &lt;&lt; std::endl;          for (auto c: hello()) std::cout &lt;&lt; c;           std::cout &lt;&lt; \"\\n\\n\";          for (auto i: fibonacci()) {  \/\/ (1)         if (i > 1'000'000) break;         std::cout &lt;&lt; i &lt;&lt; \" \";     }          std::cout &lt;&lt; \"\\n\\n\";      }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>hello<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b; \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>fibonacci<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0438\u0437 \u0440\u044f\u0434\u0430 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438. <code>fibonacci<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 (1)? \u0426\u0438\u043a\u043b <code>for<\/code> c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u041f\u0435\u0440\u0432\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>co_yield b<\/code> \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0430\u0443\u0437\u0443. \u041f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u044d\u0442\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443 <code>fibonacci<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0438\u0437 \u0440\u044f\u0434\u0430 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9a3\/101\/4db\/9a31014db2a93c839c17cd268c58a0f3.png\" width=\"602\" height=\"113\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9a3\/101\/4db\/9a31014db2a93c839c17cd268c58a0f3.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0434\u0430\u0442\u044c \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0440\u0430\u0437\u043d\u0438\u0446\u0435 \u043c\u0435\u0436\u0434\u0443 <code>co_await<\/code> (\u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438) \u0438 <code>co_yield<\/code> (\u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430): <code>co_await<\/code><strong> \u0436\u0434\u0435\u0442 \u201c\u0432\u043d\u0443\u0442\u0440\u044c\u201d, <\/strong><code>co_yield<\/code><strong> \u0436\u0434\u0435\u0442 \u201c\u043d\u0430\u0440\u0443\u0436\u0443\u201d<\/strong>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>first<\/code> \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b <code>second<\/code> (<code>cppcoroTask.cpp<\/code>), \u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>fibonacci<\/code> (<code>cppcoroGenerator.cpp<\/code>) \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0446\u0438\u043a\u043b\u043e\u043c <code>for<\/code> \u0441 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c.<\/p>\n<h4>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/h4>\n<p>\u0412 \u043c\u043e\u0435\u043c<a href=\"https:\/\/www.modernescpp.com\/index.php\/c-20-coroutine-abstraction-with-cppcoro\"> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435<\/a> \u043f\u0440\u043e cppcoro \u043c\u044b \u0443\u0433\u043b\u0443\u0431\u0438\u043c\u0441\u044f \u0432 \u0437\u0430\u0434\u0430\u0447\u0438. \u042f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u0441\u0438\u0433\u043d\u0430\u043b\u0430\u043c\u0438 \u0438\u043b\u0438 \u043f\u0443\u043b\u0430\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/p>\n<hr\/>\n<blockquote>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 &#171;C++ Developer. Professional&#187;. \u041f\u0440\u043e\u0439\u0434\u0438\u0442\u0435 <a href=\"https:\/\/otus.pw\/YXxS\/\"><strong>\u0432\u0441\u0442\u0443\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong><\/a>, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0437\u043d\u0430\u043d\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f.<\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/672838\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/672838\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 cppcoro \u043e\u0442 \u041b\u044c\u044e\u0438\u0441\u0430 \u0411\u0435\u0439\u043a\u0435\u0440\u0430 (Lewis Baker) \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0442\u043e, \u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0430\u0435\u0442 \u043d\u0430\u043c C++20 \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d C++, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043d\u0430 Coroutines TS.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0434\u0432\u0430 \u043c\u043e\u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u043f\u043e\u0441\u0442\u0430 &#171;<a href=\"https:\/\/bit.ly\/InfiniteDataStream\">C++20: \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438<\/a>&#187; \u0438 &#171;<a href=\"https:\/\/bit.ly\/ThreadSynchronizationCoroutines\">C++20: \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d<\/a>&#187; \u0431\u044b\u043b\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u041d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u0441\u0442\u044b \u043f\u0440\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043b\u0435\u0433\u0447\u0435 \u0443\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c\u0441\u044f. \u042f \u0449\u0435\u0434\u0440\u043e \u0441\u043d\u0430\u0431\u0434\u0438\u043b \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d <a href=\"https:\/\/github.com\/lewissbaker\/cppcoro\">cppcoro<\/a>.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u044f \u0445\u043e\u0447\u0443 \u043d\u0430\u0447\u0430\u0442\u044c \u0441 \u043f\u0430\u0440\u044b \u0441\u043b\u043e\u0432 \u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445 \u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d.<\/p>\n<h3>cppcoro<\/h3>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 cppcoro \u043e\u0442 \u041b\u044c\u044e\u0438\u0441\u0430 \u0411\u0435\u0439\u043a\u0435\u0440\u0430 \u0431\u0435\u0440\u0435\u0442 \u0437\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 Coroutine TS. TS \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a <em>technical specifications<\/em> (\u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438) \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432 C++20. \u041b\u044c\u044e\u0438\u0441 \u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 cppcoro \u0441 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 Coroutines TS \u043d\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432 C++20.<\/p>\n<p>\u042f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u043f\u0440\u0438\u0447\u0438\u043d\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e: <strong>\u0432 C++20 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0435 \u0441\u0430\u043c\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043a\u043e\u0440\u0443\u0442\u0438\u043d.<\/strong> \u042d\u0442\u043e\u0442 \u043d\u044e\u0430\u043d\u0441 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432 C++20, \u0442\u043e \u0432\u044b \u0441\u0430\u043c\u0438 \u043f\u043e \u0441\u0435\u0431\u0435. \u0412\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d C++20. \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u0430\u043a\u0438\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0432 C++23. \u0427\u0435\u0441\u0442\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u044f \u0441\u0447\u0438\u0442\u0430\u044e \u044d\u0442\u043e \u0447\u0440\u0435\u0437\u0432\u044b\u0447\u0430\u0439\u043d\u043e \u0432\u0430\u0436\u043d\u044b\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u0430 \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0431\u0435\u043b \u2014 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442 cppcoro. \u041e\u043d\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d, awaitable \u0442\u0438\u043f\u044b, \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043e\u0442\u043c\u0435\u043d\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (cancellation), \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0438, \u043d\u0435\u0442\u0432\u043e\u0440\u043a\u0438\u043d\u0433, \u043c\u0435\u0442\u0430\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u043e\u0432.<\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 cppcoro<\/h2>\n<p>\u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f cppcoro \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 Coroutines TS \u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 Windows (Visual Studio 2017) \u0438\u043b\u0438 Linux (Clang 5.0\/6.0 \u0438 libc++). \u0414\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432 \u043d\u0430\u0448\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u0445 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<ul>\n<li>\n<p><code>-std=c++17<\/code>: \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 C++17<\/p>\n<\/li>\n<li>\n<p><code>-fcoroutines-ts<\/code>: \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 Coroutines TS C++<\/p>\n<\/li>\n<li>\n<p><code>-Iinclude<\/code>: \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 cppcoro\u00a0<\/p>\n<\/li>\n<li>\n<p><code>-stdlib=libc++<\/code>: <a href=\"https:\/\/en.wikipedia.org\/wiki\/LLVM\">LLVM<\/a> \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/p>\n<\/li>\n<li>\n<p><code>libcppcoro.a<\/code>: \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 cppcoro<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b \u0440\u0430\u043d\u0435\u0435: \u043a\u043e\u0433\u0434\u0430 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c cppcoro \u0431\u0443\u0434\u0435\u0442 \u0430\u043a\u0442\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0434\u043e C++20, \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u043c C++20. \u0410 \u0441\u0435\u0439\u0447\u0430\u0441 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 C++23.<\/p>\n<p>cppcoro \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432 \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u0438, \u0438 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0444\u0438\u0447\u0438 cppcoro, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u0440\u0443\u0442\u0438\u043d.<\/p>\n<h2>\u0422\u0438\u043f\u044b \u043a\u043e\u0440\u0443\u0442\u0438\u043d<\/h2>\n<p>cppcoro \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0438\u0434\u044b \u0437\u0430\u0434\u0430\u0447 (task) \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 (generator).\u00a0<\/p>\n<h3>task&lt;T><\/h3>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0437\u0430\u0434\u0430\u0447\u0430? \u0412\u043e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u0432\u0437\u044f\u0442\u043e\u0435 \u043f\u0440\u044f\u043c\u0438\u043a\u043e\u043c \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430 (task) <\/strong>\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043b\u0435\u043d\u0438\u0432\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043d\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 (awaited).<\/p>\n<\/li>\n<\/ul>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u2014 \u044d\u0442\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>main<\/code> \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>first<\/code>, <code>first<\/code> \u043e\u0436\u0438\u0434\u0430\u0435\u0442 <code>second<\/code>, \u0430 <code>second<\/code> \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0442\u0440\u0435\u0442\u044c\u044e.<\/p>\n<pre><code class=\"cpp\">\/\/ cppcoroTask.cpp  #include &lt;chrono> #include &lt;iostream> #include &lt;string> #include &lt;thread>  #include &lt;cppcoro\/sync_wait.hpp> #include &lt;cppcoro\/task.hpp>  using std::chrono::high_resolution_clock; using std::chrono::time_point; using std::chrono::duration;  using namespace std::chrono_literals; \/\/ 1s     auto getTimeSince(const time_point&lt;high_resolution_clock>&amp; start) {          auto end = high_resolution_clock::now();     duration&lt;double> elapsed = end - start;     return elapsed.count();      }  cppcoro::task&lt;> third(const time_point&lt;high_resolution_clock>&amp; start) {          std::this_thread::sleep_for(1s);     std::cout &lt;&lt; \"Third waited \" &lt;&lt; getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;      co_return;                                                     \/\/ (4)          }  cppcoro::task&lt;> second(const time_point&lt;high_resolution_clock>&amp; start) {          auto thi = third(start);                                       \/\/ (2)     std::this_thread::sleep_for(1s);     co_await thi;                                                  \/\/ (3)          std::cout &lt;&lt; \"Second waited \" &lt;&lt;  getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;      }  cppcoro::task&lt;> first(const time_point&lt;high_resolution_clock>&amp; start) {          auto sec = second(start);                                       \/\/ (2)     std::this_thread::sleep_for(1s);     co_await sec;                                                   \/\/ (3)          std::cout &lt;&lt; \"First waited \" &lt;&lt;  getTimeSince(start)  &lt;&lt; \" seconds.\" &lt;&lt; std::endl;      }  int main() {          std::cout &lt;&lt; std::endl;          auto start = high_resolution_clock::now();     cppcoro::sync_wait(first(start));                              \/\/ (1)          std::cout &lt;&lt; \"Main waited \" &lt;&lt;  getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;          std::cout &lt;&lt; std::endl;  }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c, \u044d\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043e\u0441\u043e\u0431\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u0440\u0430\u0431\u044b \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>main<\/code> \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439. <code>cppcoro::sync_wait<\/code> (\u0441\u0442\u0440\u043e\u043a\u0430 (1)) \u0447\u0430\u0441\u0442\u043e \u0441\u043b\u0443\u0436\u0438\u0442 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 (\u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430). \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>first<\/code>, \u043a\u0430\u043a \u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>start<\/code> (\u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u044b) \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u044d\u0442\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435? \u041e\u043d\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443 <code>second<\/code> (\u0441\u0442\u0440\u043e\u043a\u0430 (2)), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0437\u0430\u0441\u044b\u043f\u0430\u0435\u0442 \u043d\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430 <code>sec<\/code> \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 (3). \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>second<\/code> \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441 <code>third<\/code>, \u043d\u043e \u0443 <code>third<\/code> \u0443\u0436\u0435 \u0434\u0440\u0443\u0433\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435. <code>third<\/code> \u2014 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438 \u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0434\u0440\u0443\u0433\u0443\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443. \u041a\u043e\u0433\u0434\u0430 <code>third<\/code> \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043f\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u0440\u0430\u0431\u043e\u0442\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u043e \u0442\u0440\u0438 \u0441\u0435\u043a\u0443\u043d\u0434\u044b.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0431\u0443\u0434\u0443\u0442 \u0431\u0443\u0434\u0443\u0442 \u0443\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0441\u043e\u043d \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 <code>co_await<\/code>?<\/p>\n<pre><code class=\"cpp\">\/\/ cppcoroTask2.cpp  #include &lt;chrono> #include &lt;iostream> #include &lt;string> #include &lt;thread>  #include &lt;cppcoro\/sync_wait.hpp> #include &lt;cppcoro\/task.hpp>  using std::chrono::high_resolution_clock; using std::chrono::time_point; using std::chrono::duration;  using namespace std::chrono_literals;  auto getTimeSince(const time_point&lt;::high_resolution_clock>&amp; start) {          auto end = high_resolution_clock::now();     duration&lt;double> elapsed = end - start;     return elapsed.count();      }  cppcoro::task&lt;> third(const time_point&lt;high_resolution_clock>&amp; start) {          std::cout &lt;&lt; \"Third waited \" &lt;&lt; getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;     std::this_thread::sleep_for(1s);     co_return;          }   cppcoro::task&lt;> second(const time_point&lt;high_resolution_clock>&amp; start) {          auto thi = third(start);     co_await thi;          std::cout &lt;&lt; \"Second waited \" &lt;&lt;  getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;     std::this_thread::sleep_for(1s);      }  cppcoro::task&lt;> first(const time_point&lt;high_resolution_clock>&amp; start) {          auto sec = second(start);     co_await sec;          std::cout &lt;&lt; \"First waited \" &lt;&lt;  getTimeSince(start)  &lt;&lt; \" seconds.\" &lt;&lt; std::endl;     std::this_thread::sleep_for(1s);      }  int main() {          std::cout &lt;&lt; std::endl;       auto start = ::high_resolution_clock::now();          cppcoro::sync_wait(first(start));          std::cout &lt;&lt; \"Main waited \" &lt;&lt;  getTimeSince(start) &lt;&lt; \" seconds.\" &lt;&lt; std::endl;          std::cout &lt;&lt; std::endl;  }<\/code><\/pre>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u0443\u0436\u0435 \u0438 \u0441\u0430\u043c\u0438 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>main<\/code> \u0436\u0434\u0435\u0442 \u0442\u0440\u0438 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0441\u0435\u043a\u0443\u043d\u0434\u0443.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u043f\u043e\u0441\u0442\u0430\u0445 \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 (threads) \u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u0430\u043c\u0438 (signals).\u00a0\u00a0<\/p>\n<h3>generator<\/h3>\n<p>\u0412\u043e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0442 cppcoro:<\/p>\n<ul>\n<li>\n<p><code>generator<\/code> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0438\u043f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0442\u0438\u043f\u0430 <code>T<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043b\u0435\u043d\u0438\u0432\u043e \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u0432\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0439 \u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 <code>cppcoroGenerator.cpp<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0434\u0432\u0443\u0445 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">\/\/ cppcoroGenerator.cpp  #include &lt;iostream> #include &lt;cppcoro\/generator.hpp>  cppcoro::generator&lt;char> hello() {     co_yield 'h';                       co_yield 'e';                        co_yield 'l';                        co_yield 'l';                        co_yield 'o';                    }  cppcoro::generator&lt;const long long> fibonacci() {     long long a = 0;     long long b = 1;     while (true) {         co_yield b;                 \/\/ (2)         auto tmp = a;         a = b;         b += tmp;     } }  int main() {      std::cout &lt;&lt; std::endl;          for (auto c: hello()) std::cout &lt;&lt; c;           std::cout &lt;&lt; \"\\n\\n\";          for (auto i: fibonacci()) {  \/\/ (1)         if (i > 1'000'000) break;         std::cout &lt;&lt; i &lt;&lt; \" \";     }          std::cout &lt;&lt; \"\\n\\n\";      }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>hello<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b; \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>fibonacci<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0438\u0437 \u0440\u044f\u0434\u0430 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438. <code>fibonacci<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 (1)? \u0426\u0438\u043a\u043b <code>for<\/code> c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u041f\u0435\u0440\u0432\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>co_yield b<\/code> \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0430\u0443\u0437\u0443. \u041f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u044d\u0442\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443 <code>fibonacci<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0438\u0437 \u0440\u044f\u0434\u0430 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0434\u0430\u0442\u044c \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0440\u0430\u0437\u043d\u0438\u0446\u0435 \u043c\u0435\u0436\u0434\u0443 <code>co_await<\/code> (\u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438) \u0438 <code>co_yield<\/code> (\u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430): <code>co_await<\/code><strong> \u0436\u0434\u0435\u0442 \u201c\u0432\u043d\u0443\u0442\u0440\u044c\u201d, <\/strong><code>co_yield<\/code><strong> \u0436\u0434\u0435\u0442 \u201c\u043d\u0430\u0440\u0443\u0436\u0443\u201d<\/strong>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>first<\/code> \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b <code>second<\/code> (<code>cppcoroTask.cpp<\/code>), \u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <code>fibonacci<\/code> (<code>cppcoroGenerator.cpp<\/code>) \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0446\u0438\u043a\u043b\u043e\u043c <code>for<\/code> \u0441 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c.<\/p>\n<h4>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/h4>\n<p>\u0412 \u043c\u043e\u0435\u043c<a href=\"https:\/\/www.modernescpp.com\/index.php\/c-20-coroutine-abstraction-with-cppcoro\"> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435<\/a> \u043f\u0440\u043e cppcoro \u043c\u044b \u0443\u0433\u043b\u0443\u0431\u0438\u043c\u0441\u044f \u0432 \u0437\u0430\u0434\u0430\u0447\u0438. \u042f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u0441\u0438\u0433\u043d\u0430\u043b\u0430\u043c\u0438 \u0438\u043b\u0438 \u043f\u0443\u043b\u0430\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/p>\n<hr\/>\n<blockquote>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 &#171;C++ Developer. Professional&#187;. \u041f\u0440\u043e\u0439\u0434\u0438\u0442\u0435 <a href=\"https:\/\/otus.pw\/YXxS\/\"><strong>\u0432\u0441\u0442\u0443\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong><\/a>, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0437\u043d\u0430\u043d\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f.<\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/672838\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/672838\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-334839","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=334839"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334839\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=334839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=334839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=334839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}