{"id":413583,"date":"2024-06-29T23:12:58","date_gmt":"2024-06-29T23:12:58","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=413583"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=413583","title":{"rendered":"<span>CoroOS: \u043a\u043e\u043d\u0446\u0435\u043f\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0434\u043b\u044f \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u0440\u043e\u0432 \u043d\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445 \u0421++20<\/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<p>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440, \u0438 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u043c \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432.<\/p>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043b\u044e\u0431\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u043e\u0434\u0443\u043c\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043e\u0441\u044c. \u0414\u0430 \u0442\u0430\u043a\u0443\u044e, \u0447\u0442\u043e\u0431\u044b \u0434\u0440\u0443\u0433\u0438\u043c \u043d\u0435\u043f\u043e\u0432\u0430\u0434\u043d\u043e \u0431\u044b\u043b\u043e!<\/p>\n<p>\u0418 \u0432\u0430\u0448 \u0430\u0432\u0442\u043e\u0440 \u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. <\/p>\n<p>\u041a\u0430\u043a \u043f\u043e \u043c\u043d\u0435 &#8212; \u0434\u0435\u043b\u043e \u043d\u0435 \u0442\u043e \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u0435\u0434\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0435, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0440\u043e\u043f\u043e\u0442\u043b\u0438\u0432\u043e\u0435. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441, \u043a\u0430\u043a \u0438 \u0443 \u043c\u0435\u043d\u044f, \u0443\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043a\u0430\u0440\u044c\u0435\u0440\u0430 \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f \u0432\u043e\u043a\u0440\u0443\u0433 Arm Cortex-M \u0441\u0435\u0440\u0438\u0438, \u0442\u043e \u0432\u043e\u043e\u0440\u0443\u0436\u0430\u0435\u043c\u0441\u044f \u0441\u0442\u0432\u043e\u043b\u0430\u043c\u0438 (<a href=\"https:\/\/www.amazon.com\/Definitive-Guide-Cortex%C2%AE-M3-Cortex%C2%AE-M4-Processors\/dp\/0124080820\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0437<\/a>, <a href=\"https:\/\/www.amazon.com\/Designers-Guide-Cortex-M-Processor-Family\/dp\/0081006292\/ref=pd_bxgy_1\/142-2669340-8725063?pd_rd_w=FuhFp&amp;pf_rd_p=c64372fa-c41c-422e-990d-9e034f73989b&amp;pf_rd_r=S5PTR4Z07FP5KDD7ESQN&amp;pd_rd_r=2a860679-0d9d-4aef-a532-19e1b6de649b&amp;pd_rd_wg=xprvE&amp;pd_rd_i=0081006292&amp;psc=1\" rel=\"noopener noreferrer nofollow\">\u0434\u0432\u0430<\/a> \u0438 <a href=\"https:\/\/developer.arm.com\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0440\u0438<\/a>) \u0438 \u0432\u044b\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0437\u0430 <a href=\"https:\/\/aws.amazon.com\/ru\/freertos\/\" rel=\"noopener noreferrer nofollow\">\u0414\u0436\u0435\u0444\u0444\u043e\u043c<\/a>. <\/p>\n<p>\u041d\u043e, \u043d\u0430\u043f\u0438\u0441\u0430\u0432  \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u044f\u0434\u0440\u043e \u0441\u0432\u043e\u0435\u0439 &#171;best of the best&#187; \u043e\u0441\u0438 \u043e\u043a\u043e\u043b\u043e \u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434, \u044f \u0432\u0441\u043a\u043e\u0440\u0435 \u0437\u0430\u0431\u0440\u043e\u0441\u0438\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443. \u0418\u0431\u043e \u043a\u0430\u043a \u044f \u043d\u0438 \u043a\u0440\u0435\u0430\u0442\u0438\u0432\u0438\u043b, \u0432\u043c\u0435\u0441\u0442\u043e \u0421\u043e\u043a\u043e\u043b\u0430 \u0422\u044b\u0441\u044f\u0447\u0435\u043b\u0435\u0442\u0438\u044f \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0441\u044f \u043a\u0440\u0435\u043f\u0435\u043d\u044c\u043a\u0438\u0439, \u043d\u043e \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0438 \u0441\u043a\u0443\u0447\u043d\u044b\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434.<\/p>\n<p>\u0410 \u0432\u0435\u0434\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0431\u0435\u0441\u0441\u0442\u044b\u0434\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u0435\u043d\u0434\u0440\u0451\u0436\u0430.<\/p>\n<p>\u0418 \u0442\u0443\u0442 \u0432 20-\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u0437\u0430\u0432\u0435\u0437\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. <\/p>\n<p>\u0412\u043e\u0442 \u044d\u0442\u043e \u0432\u043e\u0442 \u0432\u0441\u0451:<\/p>\n<pre><code class=\"cpp\">#include &lt;coroutine>  Coro task(){      foo();      co_await awaitable_1();      bar();      auto res = co_await awaitable_2();      func(res);  }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0430\u0448\u0430 \u0447\u0443\u0439\u043a\u0430 \u044d\u043c\u0431\u0435\u0434\u0434\u0435\u0440\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u043d\u0443\u0442\u044c: &#171;\u0410 \u0435\u0441\u043b\u0438 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u043d\u043e \u0441 \u043f\u0435\u0440\u043b\u0430\u043c\u0443\u0442\u0440\u043e\u0432\u044b\u043c\u0438 \u043f\u0443\u0433\u043e\u0432\u0438\u0446\u0430\u043c\u0438?&#187; :<\/p>\n<pre><code class=\"cpp\">#include &lt;coroutine>  Coro task1() {    while (true) {     \/\/ \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043d\u0435\u043a\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435     co_await event.get();     \/\/ \u043f\u043e \u0435\u0433\u043e \u043d\u0430\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044e \u0431\u043b\u0438\u043d\u043a\u0430\u0435\u043c     toggle_led();     \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0430\u0439\u043c\u0435\u0440 \u043d\u0430 250 \u043c\u0441\/\u0441\/\u043c\u0438\u043d \u0438 \u0436\u0434\u0435\u043c     co_await timer.get(250);     \/\/ \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u0441\u043d\u043e\u0432\u0430 \u0431\u043b\u0438\u043d\u043a\u0430\u0435\u043c     toggle_led();     \/\/ \u0438 \u0432\u0441\u0435 \u043f\u043e \u043d\u043e\u0432\u043e\u0439    } }<\/code><\/pre>\n<p>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0442\u0438\u043f\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u0420\u0422\u041e\u0421. \u041f\u0440\u0438\u0447\u0435\u043c \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u043e\u0437\u044c\u043c\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0440\u0430\u0441\u0447\u0435\u0442 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0434 \u0437\u0430\u0434\u0430\u0447\u0443. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u0443\u0447\u0435\u0441\u0442\u044c. \u041d\u0430\u043c \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u0438, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e \u043f\u043e\u0434 \u0432\u0441\u0435 \u0437\u0430\u0434\u0430\u0447\u0438. \u0423\u0436\u0435 \u043d\u0435\u043f\u043b\u043e\u0445\u043e. <\/p>\n<p>\u0424\u0430\u043d\u0442\u0430\u0437\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435. \u0411\u0443\u0434\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u043e, \u0435\u0441\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 co_await \u0441\u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u0435\u0434\u0438\u043d\u044b\u043c \u043e\u043a\u043d\u043e\u043c \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439, \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u043e\u043c \u0438 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430\u043c\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 (\u044d\u0432\u0435\u043d\u0442\u044b, \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b, \u0442\u0430\u0439\u043c\u0435\u0440\u044b, \u043e\u0447\u0435\u0440\u0435\u0434\u0438 etc.). \u0422\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c  \u0432\u044b\u0438\u0433\u0440\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430. <\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e, \u0430 \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430\u043c\u0438 \u0437\u0430\u0434\u0430\u0447? \u0410 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u0440\u0437\u043d\u0443\u0442\u044c, \u0432\u044b\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0435 \u043d\u0430\u0438\u0437\u043d\u0430\u043d\u043a\u0443 \u0438 \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0441 <em>\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c<\/em> \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f :<\/p>\n<pre><code class=\"cpp\">#include &lt;coroutine>  Coro task2(){      while(true){     \/\/ \u0436\u0434\u0435\u043c \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u043e\u0442 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c     co_await queue.get&lt;CoPrio::normal>();     \/\/ \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430     auto payload = queue.unload();     \/\/ \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u043c\u044e\u0442\u0435\u043a\u0441. \u0415\u0441\u043b\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c     \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441\u0440\u0430\u0437\u0443. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442 - \u0436\u0434\u0435\u043c \u0435\u0433\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f      co_await mutex.get&lt;CoPrio::low>();     \/\/ \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043d\u0435\u043a\u0438\u043c \u043e\u0431\u0449\u0438\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043d\u0438\u0437\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430     shared_bus_send(res);     \/\/ \u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441     mutex.give();     \/\/ \u0436\u0434\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0441 \u0432\u044b\u0441\u043e\u043a\u0438\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c     co_await event.get&lt;CoPrio::high>();     \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u0440\u043e\u0447\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430     very_urgent_func();   } }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0437\u0430\u043c\u0430\u043d\u0447\u0438\u0432\u043e.<\/p>\n<p>\u041e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043d\u0430\u0432\u0435\u0441\u0438\u0442\u044c \u0441\u044e\u0434\u0430 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440, \u0436\u043e\u043d\u0433\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043d\u0430\u0448\u0438\u043c\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438, \u043f\u043b\u044e\u0441 context switcher, \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u0447\u0442\u043e \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e\u0435. \u041f\u043e\u0445\u043e\u0436\u0435, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u0443 \u0438 \u0445\u0430\u0439\u043f\u0430\u043d\u0443\u0442\u044c \u043d\u0430 \u0433\u043e\u0440\u044f\u0447\u0435\u043d\u044c\u043a\u043e\u0439 \u0435\u0449\u0435 \u0442\u0435\u043c\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d &#8212; \u043a\u0430\u043a \u0436\u0435 \u0431\u0435\u0437 \u044d\u0442\u043e\u0433\u043e \ud83d\ude42<\/p>\n<p>\u0414\u043b\u044f \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u043e\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u0430\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0432\u043e\u0434\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u0435\u0435 \u043f\u043e \u0445\u043e\u0434\u0443 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<ul>\n<li>\n<p>\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0447\u0442\u043e \u0432\u044b \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043a \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044e \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e <a href=\"https:\/\/habr.com\/ru\/company\/yandex\/blog\/420861\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a>. \u0422\u0430\u043a\u0436\u0435 \u0437\u0430\u0431\u0443\u0440\u0438\u0442\u044c\u0441\u044f \u0432 \u0442\u0435\u043c\u0443 \u043f\u043e\u0433\u043b\u0443\u0431\u0436\u0435 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/habr.com\/ru\/company\/wunderfund\/blog\/582000\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441 \u043a\u043e\u0434\u043e\u043c \u0438 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u0430\u043c \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044f, \u044f \u0431\u0443\u0434\u0443 \u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043a\u0432\u0430\u043b\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0438\u0437 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\/\u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0440\u0430\u0431\u043e\u0447\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044f \u0434\u0430\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438. <\/p>\n<\/li>\n<li>\n<p>\u0432\u0430\u0436\u043d\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u0441\u0442\u0430\u0442\u044c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043a\u043e\u0434\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043b\u0435\u0435 &#8212; \u0432\u0434\u0443\u043c\u0447\u0438\u0432\u044b\u0439 \u043b\u043e\u043d\u0433\u0440\u0438\u0434. \u0412\u0441\u0435-\u0442\u0430\u043a\u0438 \u043e\u0441\u044c \u043f\u0438\u0448\u0435\u043c, \u0430 \u043d\u0435 \u043c\u043e\u0440\u0433\u0430\u043b\u043a\u0443 \u0430\u0440\u0434\u0443\u0438\u043d\u043e\u0432\u0441\u043a\u0443\u044e.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e-\u043d\u0430\u043f\u0435\u0440\u0432\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0435\u043a\u0438\u0439 \u0441\u0438\u043d\u0445\u0440\u043e-\u043e\u0431\u044a\u0435\u043a\u0442, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439 \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043c\u0438\u0440\u043e\u043c. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"cpp\">#include \"co_types.hpp\"  struct CoSync{   co_mutex_t mutex;  \/\/ \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430      \/\/ \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0433\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043e CoMutex   void* co_addr;     \/\/ \u0430\u0434\u0440\u0435\u0441 coroutine_handle   CoState state;     \/\/ \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b (\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 etc.)   CoPrio prio;       \/\/ \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442   base_t id;         \/\/ \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440   base_t size;       \/\/ \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043f\u0430\u043c\u044f\u0442\u0438   co_act_t expected; \/\/ \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 };  \/\/ \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0430\u043b\u0438\u0430\u0441 \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 CoSync using co_sync_t = CoSync*;<\/code><\/pre>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0439; \u043c\u044b \u0432\u043e\u043b\u044c\u043d\u044b \u043f\u0440\u0438 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u043e\u0432\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 promise_type \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u043d\u0430\u0431\u043e\u0440  \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Promise \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/coroutines#co_await\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<pre><code class=\"cpp\">#include &lt;coroutine> #include &lt;limits>  #include \"co_proxy.hpp\" #include \"co_alloc.hpp\"  struct Coro {      using promise_type = Coro;      CoSync sync {     .mutex{.ptr = nullptr, .is_taken = false},     .co_addr{nullptr},     .state{CoState::stopped},     .prio{CoPrio::lowest},     .id{ indexer_t{}() }, \/\/ \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 id     \/\/ \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b     .size{0},     .expected{std::numeric_limits&lt;co_act_t>::max()},   };      auto get_return_object() { return Coro{}; }      std::suspend_never initial_suspend() {     \/\/ \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430,     \/\/ \u043c\u0435\u043d\u044f\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0430 \"\u0433\u043e\u0442\u043e\u0432\u0430\"     sync.state = CoState::ready;     \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u043f\u0430\u043c\u044f\u0442\u0438     sync.size = CoAlloc::get_current_size();     return {};   }      template&lt;co_act_t ID, CoPrio P>   auto yield_value ( co_proxy_t&lt;ID, P> p) {          struct Awaitable{ \/* \u0441\u043c. \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0438\u0436\u0435 *\/ };          return Awaitable{p}; }      template&lt;co_act_t ID, CoPrio P>   auto await_transform(co_proxy_t&lt;ID, P> p) {     return yield_value&lt;ID, P>(p);   }      void* operator new(std::size_t sz){     \/\/ \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u043b\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439     \/\/ \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 new, \u0441\u0442\u043e\u0431\u044b \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c     \/\/ \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u043c. \u041a\u0430\u043a \u0438 \u0433\u0434\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c.     return CoAlloc::allocate(sz); }  void operator delete( void* p){     CoAlloc::deallocate(p);   } }; <\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0435\u0436\u0438\u043c\u0441\u044f \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437 \u0438 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u0432 promise_type.<\/p>\n<p>\u0412 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043c\u044b \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0435\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440. \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0438\u0441\u043b\u043e \u043e\u0442 0 \u0434\u043e \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u0434\u0430\u0447, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435. \u0415\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435  &#8212; \u0441\u043b\u0443\u0436\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0441\u0438\u043d\u0445\u0440\u043e-\u043e\u0431\u044a\u0435\u043a\u0442\u044b CoSync. \u0418\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u043c\u044b \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0442\u0438\u043f\u0430 indexer_t :<\/p>\n<pre><code class=\"cpp\">using indexer_t = decltype( []{ static base_t i; return ++i - 1; } );<\/code><\/pre>\n<p>\u0418\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0441\u0442\u0432\u043e? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0435\u0434\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u041d\u043e \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435\u0437\u0434\u043e\u0440\u041e\u0432\u043e \u0444\u0430\u043d\u0430\u0442\u0435\u044e \u043f\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044e \u043b\u043e\u0433\u0438\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u0442\u0438\u043f\u044b. \u0422\u0438\u043f\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043c\u0435\u0441\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0435 \u0437\u0430\u043c\u0443\u0441\u043e\u0440\u0438\u0432\u0430\u044f \u043a\u043e\u0434 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438. \u0422\u0438\u043f\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0445\u0430\u0442\u044c \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u044b, \u043f\u043e\u043c\u043e\u0433\u0430\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c \u043a\u043e\u0434, \u043f\u0435\u0440\u0435\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 \u043a\u043e\u043c\u043f\u0430\u0439\u043b \u0442\u0430\u0439\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0442\u0435\u0440\u043f\u0438\u0442\u0435 \u0447\u0443\u0442\u043a\u0430:)<\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 Awaitable:<\/p>\n<pre><code class=\"cpp\">#include &lt;coroutine>  struct Awaitable{   \/\/ \u043e\u0431\u044a\u0435\u043a\u0442 proxy \u043f\u0440\u0438 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 Awaitable \u0432   \/\/ \u043c\u0435\u0442\u043e\u0434\u0435 yield_value \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 p,   \/\/ \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 (\u044d\u0432\u0435\u043d\u0442, \u043e\u0447\u0435\u0440\u0435\u0434\u044c etc.).   \/\/ proxy - \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 co_proxy_t(\u0441\u043c. \u043d\u0438\u0436\u0435),    \/\/ \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c   \/\/ \u043e\u043d \u0441\u043b\u0443\u0436\u0438\u0442 \u043a\u0430\u043d\u0430\u043b\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u043d\u0444\u043e \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438   \/\/ \u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439.   co_proxy_t&lt;ID, P> proxy;      \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 proxy \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430.   \/\/ \u043f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443 \u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c   \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438   bool await_ready () {     \/\/ \u0435\u0441\u043b\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u043b\u0441\u044f - \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e     \/\/ \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u0441\u044f.     if (not proxy.mutex.ptr) return false;          \/\/ \u0438\u043d\u0430\u0447\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0444\u043b\u0430\u0433 \u0437\u0430\u0445\u0432\u0430\u0442\u0430 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u043c \u043f\u043e     \/\/ \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e     return proxy.mutex.is_taken;   }      void await_suspend (std::coroutine_handle&lt;promise_type> coro) {     \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u043f\u043e\u043b\u044f sync \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 promise \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b      co_sync_t sync = &amp;coro.promise().sync;          \/\/ \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 co_await \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c     \/\/ \u043d\u0430 sync \u0432 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0435. co_proxy_t \u0437\u043d\u0430\u0435\u0442 \u043e \u0442\u0438\u043f\u0435     \/\/ \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c     \/\/ \u043c\u0435\u0442\u043e\u0434\u0430\u043c     if (CoState::ready == sync->state)                     decltype(proxy)::store_sync(sync);          \/\/ \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 sync: \u0430\u0434\u0440\u0435\u0441 cooutine_handle,     \/\/ \u043d\u043e\u0432\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430, \u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435.     \/\/ \u0442\u0430\u043a\u0436\u0435 \u043c\u0435\u043d\u044f\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043d\u0430 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0435      sync->co_addr = coro.address();     sync->mutex = proxy.mutex;     sync->state = CoState::suspended;     sync->prio = P;     sync->expected = ID;   }      \/\/ \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043e\u0441\u0438 \u044f \u043f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0443\u0436\u043d\u043e   \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 co_yield, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u043a\u0430 0   auto await_resume () { return 0; } }; <\/code><\/pre>\n<p>\u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u044e\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0432 \u043a\u0443\u0447\u0435. \u0414\u043b\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u043b\u043e\u0432\u043e &#171;\u043a\u0443\u0447\u0430&#187; \u043f\u043e\u0447\u0442\u0438 \u0440\u0443\u0433\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e. \u0425\u043e\u0440\u043e\u0448\u0438\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u041f\u041e, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0441\u0430\u043c \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043c\u0443, \u0433\u0434\u0435 \u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438. \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0431\u044b\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u043c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440. \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430 \u0438 \u0437\u0430\u044e\u0437\u0430\u0435\u043c std::pmr::monotonic_buffer_resource. \u041e\u043d \u0431\u044b\u0441\u0442\u0440\u044b\u0439, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b (de)allocate() : <\/p>\n<pre><code class=\"cpp\">\/\/ in co_alloc.cpp  #include &lt;memory_resource> #include \"co_alloc.hpp\"  byte_t raw_buf[CoParam::CORO_STORAGE_SIZE];  std::pmr::monotonic_buffer_resource mbr{raw_buf, CoParam::CORO_STORAGE_SIZE};  \/\/ \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f current_size \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \/\/ \u043a\u043e\u043b-\u0432\u0430 \u0431\u0430\u0439\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438. \/\/ max_size - \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0432\u0441\u0435\u043c\u0438 \/\/ \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 std::size_t current_size, max_size;<\/code><\/pre>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f CoAlloc \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430(\u0432\u0442\u043e\u0440\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u043e\u043f\u0443\u0449\u0435\u043d\u044b):<\/p>\n<pre><code class=\"cpp\">\/\/ in co_alloc.hpp  struct CoAlloc{   static void* allocate (std::size_t size);   static void deallocate (void *p);   static std::size_t get_current_size();   static std::size_t check_memory(); };  \/\/ in co_alloc.cpp  void* CoAlloc::allocate(std::size_t size){   current_size = size;   max_size += size;   return mbr.allocate(size); }  void CoAlloc::deallocate([[maybe_unused]] void *p){   \/\/ \u043c\u0435\u0442\u043e\u0434 release() \u043a\u043b\u0430\u0441\u0441\u0430 monotonic_buffer_resource   \/\/ \u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u0432\u0441\u044e \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c mbr   \/\/ \u043f\u0430\u043c\u044f\u0442\u044c. \u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u0448\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u0440\u0443\u0442\u044f\u0442\u0441\u044f   \/\/ \u0432 infinite loop, \u043c\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u044e\u0434\u0430 \u043f\u043e\u043f\u0430\u0441\u0442\u044c.   \/\/ \u043d\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u0430\u043b\u0438, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0441\u0443\u0448\u0438\u043c \u0432\u0435\u0441\u043b\u0430.   mbr.release();   std::abort(); }  std::size_t CoAlloc::get_current_size(){   return current_size; }  std::size_t CoAlloc::check_memory(){   return max_size; }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. <\/p>\n<p>\u0422\u043e\u0447\u043a\u0430 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f(\u0438\u043b\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430, \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 etc.) &#8212; \u044d\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 co_await. \u0427\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u043d\u0430\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0442\u0438\u043f\u0430 co_proxy_t. \u042d\u0442\u043e \u0430\u043b\u0438\u0430\u0441 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:<\/p>\n<pre><code class=\"cpp\">\/\/ in co_proxy.hpp  template&lt;co_act_t ID, CoPrio P> struct CoProxyData final : public CoManager {   co_mutex_t mutex{     .ptr = nullptr,     .is_taken = false     }; };  template&lt;co_act_t ID, CoPrio P> using co_proxy_t = CoProxyData&lt;ID, P>;<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, \u0442\u0438\u043f co_proxy_t \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0437\u043d\u0430\u043d\u0438\u0435 \u043e \u0442\u0438\u043f\u0435 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430 (\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 CoManager, \u043e \u043d\u0435\u0439 \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435), \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f (\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440  \u0410) \u0438 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0435 (\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440  P). \u041d\u043e \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442\u044c \u0435\u0434\u0438\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438? <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 CoProxy. \u041e\u0442 \u043d\u0435\u0433\u043e \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <a href=\"https:\/\/ru.wikipedia.org\/wiki\/Curiously_recurring_template_pattern\" rel=\"noopener noreferrer nofollow\">\u043f\u0430\u0442\u0442\u0435\u0440\u043d CRTP<\/a>, \u0432 \u043a\u043e\u043c\u043f\u0430\u0439\u043b \u0442\u0430\u0439\u043c\u0435 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u044b \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432.<\/p>\n<pre><code class=\"cpp\">\/\/ in co_proxy.hpp  #include \"co_util.hpp\" #include \"co_manager.hpp\"  template&lt;typename T> class CoProxy : public CoManager {      public:   using derived_ptr = T*; \/\/ \u0430\u043b\u0438\u0430\u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u044b\u0439 \u043a\u043b\u0430\u0441\u0441      \/\/ \u043c\u0435\u0442\u043e\u0434 give() \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440   \/\/ \u043d\u0430\u0441\u0442\u0443\u043f\u0438\u0432\u0448\u0435\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u043c\u0435\u0442\u043e\u0434 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0434\u0432\u0443\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439    \/\/ \u043a\u0430\u043d\u0430\u043b \u0441\u0432\u044f\u0437\u0438 - \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0447\u0435\u0440\u0435\u0437 pack   \/\/ \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u041f\u0440\u0438\u043c\u0435\u0440 \u0443\u0432\u0438\u0434\u0438\u043c   \/\/ \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430   template&lt;typename ...Args> void give(Args&amp;&amp; ...args) {          \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430-\u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 id \u0441\u043e\u0431\u044b\u0442\u0438\u044f     co_act_t action =        derived()->give_impl(co_detail::forward&lt;Args>(args) ...);     \/\/ \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430       set_action(action); }      \/\/ \u043c\u0435\u0442\u043e\u0434 get() \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u0439    \/\/ \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 co_proxy_t,   \/\/ \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 co_await.   template&lt;CoPrio P, typename ...Args>   auto get (Args&amp;&amp; ...args) {     return derived()->template get_impl&lt;P>(co_detail::forward&lt;Args>(args) ...); }   \/\/ \u043c\u0435\u0442\u043e\u0434 ready() \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e \u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430   \/\/ \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044e.   \/\/ \u041f\u0440\u0438\u043c\u0435\u0440 \u0443\u0432\u0438\u0434\u0438\u043c \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.    bool ready() {     return derived()->ready_impl(); }      \/\/ \u0435\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0441\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443,   \/\/ \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0435\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u043c unload(). \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043d\u0438\u0436\u0435.   auto unload() {     return derived()->unload_impl(); }  private:    derived_ptr derived() {     return static_cast&lt;derived_ptr>(this); } };<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0438 \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e co_detail::forward&lt;Args>(args). \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u043a\u0430 \u043d\u0430\u0448\u0430 \u041e\u0421 \u0432 \u0437\u0430\u0447\u0430\u0442\u043e\u0447\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u044f\u043d\u0438\u0438, \u043c\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u043c \u0432\u0441\u0435\u0445 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0435\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0437\u0443\u043c\u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0437\u0430\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0432\u0430\u0440\u0438\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438. \u0418\u0441\u043f\u043e\u043b\u043d\u0438\u043c \u044d\u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0438 perfect forwarding. \u041d\u0443 \u0430 \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0438\u043d\u043a\u043b\u044e\u0434\u0438\u0442\u044c \u0441\u043a\u0432\u043e\u0437\u044c \u0432\u0435\u0441\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0435\u0445\u0438\u043b\u044b\u0439 \u0442\u0430\u043a\u043e\u0439 \u0445\u0435\u0434\u0435\u0440 &lt;utility>, \u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b move(), forward() \u0432 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u0438\u043a\u0435&#187;co_util.hpp&#187;, \u0432 \u043d\u044d\u0439\u043c\u0441\u043f\u0435\u0439\u0441\u0435 co_detail, \u0431\u043b\u0430\u0433\u043e \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u0445(<a href=\"https:\/\/stackoverflow.com\/questions\/27501400\/the-implementation-of-stdforward\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0438\u043c\u0435\u0440<\/a>).<\/p>\n<p>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u044f \u0438 \u0434\u0430\u043b\u0435\u0435 \u043f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0443 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u0441\u0432\u043e\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u0438\u043a\u0438 &#171;\u0442\u044f\u0436\u0435\u043b\u044b\u0445&#187; \u0445\u0435\u0434\u0435\u0440\u043e\u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (\u0431\u0443\u0434\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 .cpp \u0444\u0430\u0439\u043b\u0430\u0445 \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0441\u0432\u043e\u044e \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u0443\u044e \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432). \u0426\u0435\u043b\u044c \u043f\u0440\u043e\u0441\u0442\u0430 \u0438 \u0431\u043b\u0430\u0433\u043e\u0440\u043e\u0434\u043d\u0430 &#8212; \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0441\u0435\u0431\u0435 \u0438 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043d\u0430 \u0441\u0431\u043e\u0440\u043a\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0440\u0435\u0447\u044c \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0434\u0435\u0442 \u043e \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445, \u043d\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438&#8230;<\/p>\n<p>\u041d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u0447\u0435\u0440\u0435\u0434\u0438. \u041a\u043b\u0430\u0441\u0441 CoQueue \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">\/\/ in \"co_queue.hpp\"  #include \"co_variant.hpp\" #include \"co_queue_impl.hpp\" #include \"co_proxy.hpp\"  template&lt;co_act_t A> class CoQueue final: public CoProxy&lt;CoQueue&lt;A>>{      public:   \/\/ \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 CoQueueImpl \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043b\u043e\u0433\u0438\u043a\u0443   \/\/ \u043e\u0447\u0435\u0440\u0435\u0434\u0438. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0443\u0435\u043c \u0435\u0433\u043e \u0442\u0438\u043f\u043e\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438   \/\/ \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0438 \u0442\u0438\u043f\u043e\u043c \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u043c \u0437\u0430 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0441\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439   using co_queue_t =      CoQueueImpl&lt;co_payload_t, CoParam::CORO_QUEUE_SIZE, co_critical_t>;      \/\/ \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 give_impl() \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438   \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c id \u0434\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.    \/\/ \u043a\u0430\u043a \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 give() \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u044d\u0442\u043e\u0442   \/\/ id \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0443 \u0434\u043b\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f   \/\/ \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b   co_act_t give_impl(const co_payload_t&amp; payload) {          instance().push(payload);     return A;   }      \/\/ \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u0435\u043c \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e   \/\/ \u0441\u043e\u0431\u044b\u0442\u0438\u0438, \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0435, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e - \u043f\u0443\u0441\u0442\u044b\u0435)   \/\/ \u0438 \u0442\u0438\u043f\u0435 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430   template&lt;CoPrio P>   co_proxy_t&lt;A, P> get_impl() { return {}; }      \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u0430\u043d\u043d\u044b\u0435   bool ready_impl() {     return !instance().is_empty();   }      \/\/ \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u044c   co_payload_t unload_impl() {     return instance().pop();   }      private:   \/\/ \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c instance() \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438   \/\/ \u043e\u0431\u044a\u0435\u043a\u0442\u0430 co_queue \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 queue_impl   \/\/ \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0433\u043e \u043f\u0440\u0438 \u0432\u0441\u0435\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445.   [[gnu::always_inline]] co_queue_t&amp; instance() {     static  co_queue_t queue_impl;     return queue_impl;   } };  \/\/ \u0434\u0435\u0444\u0430\u0439\u043d \u0443\u043f\u0440\u043e\u0449\u0430\u0449\u044e\u0449\u0438\u0439 \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 #define CO_QUEUE(q)   using q = CoProxy&lt;CoQueue&lt;__COUNTER__>>  \/*  USER SECTION START  *\/ \/\/ \u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0441\u0435\u043a\u0446\u0438\u0438 \u0437\u0430\u0434\u0430\u0435\u043c \u0442\u0438\u043f\u044b \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 \u0438  \/\/ \u0438 \u0434\u0430\u043b\u0435\u0435 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u0443\u0435\u043c \u0438 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0433\u0434\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c  \/\/ \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u043d\u043e\u0432\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u044d\u0442\u043e\u0433\u043e \u0436\u0435 \u0442\u0438\u043f\u0430 \u0431\u0443\u0434\u0435\u0442 \/\/ \u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 \u043d\u0438\u043c. CO_QUEUE(spi_queue_t); CO_QUEUE(uart_queue_t); \/*  USER SECTION end  *\/<\/code><\/pre>\n<p>\u0421 \u043a\u043b\u0430\u0441\u0441\u043e\u043c CoQueueImpl \u044f \u0432\u0430\u0441 \u043d\u0438\u0447\u0435\u043c \u043d\u0435 \u0443\u0434\u0438\u0432\u043b\u044e, \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u041e\u0421 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u0430:<\/p>\n<pre><code class=\"cpp\">\/\/ in \"co_queue_impl.hpp\"  #include \"critical_section.hpp\" #include \"co_types.hpp\"  template&lt;typename P, CoParam D, typename CS> class CoQueueImpl{  public:    void push (const P&amp; payload) {   CS critical_section;      queue[head] = payload;      ++head;      if (D == head) head = 0; }  P pop () {   CS critical_section;          base_t current = tail;          ++tail;          if (D == tail) tail = 0;          return queue[current]; }      P back() {     return queue[tail];   }  bool is_empty() { return head == tail; }  auto&amp; get_instance() { return queue; }  private: P queue[D];   base_t head{0}, tail{0}; };<\/code><\/pre>\n<p>\u0412 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043a\u043b\u0430\u0441\u0441\u0435 CoQueue \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0437\u0430\u0434\u0430\u043d \u043d\u0435\u043a\u0438\u0439 \u0442\u0438\u043f co_payload_t.  \u042d\u0442\u043e \u0430\u043b\u0438\u0430\u0441 \u043d\u0430 \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u043d\u044b\u0439 (\u043e\u0442\u0441\u044b\u043b\u043a\u0430 \u043a \u043c\u043e\u0435\u043c\u0443 \u0431\u0437\u0438\u043a\u0443 \u043e\u0431 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438) \u0430\u043d\u0430\u043b\u043e\u0433 std::variant &#8212; \u043a\u043b\u0430\u0441\u0441 CoVariant. \u0412 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0442.\u043d. tagged union. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439, \u0442\u043e \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0438\u0434\u0435\u044e \u0443\u0440\u0435\u0437\u0430\u043d\u043d\u043e\u0439 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0435\u0439 CoVariant \u043d\u0438\u0436\u0435. \u041f\u043e\u043b\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438. \u041f\u043e\u043a\u0430 \u043d\u0430\u0448 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0433\u043e\u0442\u043e\u0432 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u044b uint32_t \u0438 void*. \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0435\u0433\u043e \u043d\u043e\u0432\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 &#8212; \u0432\u043e\u043f\u0440\u043e\u0441 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0430. \u041d\u0443 \u0430 \u0435\u0441\u043b\u0438 \u0432\u0430\u0441 \u043d\u0435 \u0442\u0440\u0435\u0432\u043e\u0436\u0438\u0442 \u0432\u0440\u0435\u043c\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0435\u0433\u043e \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 std::variant. <\/p>\n<pre><code class=\"cpp\">\/\/ in \"co_variant.hpp\"  class CoVariant{      public:   CoVariant(const CoVariant&amp; other) : tag(other.tag){          switch(tag){                case Tag::NONE:         val = 0;         break;              case Tag::BASE_T:         val = other.val;         break;              case Tag::VOID_PTR:         ptr = other.ptr;         break;     }   }      private:      enum class Tag{NONE, VOID_PTR, BASE_T};   Tag tag{Tag::NONE};      union{         void* ptr;         base_t val;     }; }; <\/code><\/pre>\n<p>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043b\u0430\u0441\u0441\u0430 CoMutex \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0442\u043e\u0439 \u0436\u0435 \u043b\u043e\u0433\u0438\u043a\u0435, \u0447\u0442\u043e \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0439 \u0440\u0430\u043d\u0435\u0435 \u043a\u043b\u0430\u0441\u0441 CoQueue. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430, \u043f\u0440\u043e\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cpp\">\/\/ in \"co_types.hpp\"  \/\/ \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 struct CoMutexData{     bool* ptr; \/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043c\u044c\u044e\u0442\u0435\u043a\u0441     bool is_taken; \/\/ \u0444\u043b\u0430\u0433 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u0432\u0437\u044f\u0442\u0438\u044f \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 };  using co_mutex_t = CoMutexData;  \/\/ in \"co_mutex.hpp\"  #include \"critical_section.hpp\" #include \"co_proxy.hpp\"  template&lt;typename CS> class CoMutexImpl{  public:    co_mutex_t get_mutex() {   CS critical_section;     \/\/ \u0435\u0441\u043b\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0441\u0432\u043e\u0431\u043e\u0434\u0435\u043d, \u0444\u043b\u0430\u0433 is_taken = true     bool is_taken = !mutex;     \/\/ \u0437\u0430\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u044c\u0442\u0435\u043a\u0441     if (is_taken) mutex = true;          return {&amp;mutex, is_taken};   }    void give_mutex() { mutex = false; }  private: bool mutex{false}; };  template&lt;co_act_t A> class CoMutex final : public CoProxy&lt;CoMutex&lt;A>>{      public:      co_act_t give_impl() {     instance().give_mutex();     return A; };      template&lt;CoPrio P>   co_proxy_t&lt;A, P> get_impl() {     \/\/ \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430     return {.mutex = instance().get_mutex(),};   }      private:   using mutex_impl_t = CoMutexImpl&lt;co_critical_t>;      [[gnu::always_inline]] mutex_impl_t&amp; instance() {     static mutex_impl_t mutex_impl;     return mutex_impl;   } };  #define CO_MUTEX(n)   using n = CoProxy&lt;CoMutex&lt;__COUNTER__>>  \/*  USER SECTION START  *\/ CO_MUTEX(dma_mutex_t); \/*  USER SECTION END  *\/<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0438\u0437 std::chrono. \u041d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u0430\u0448 \u0440\u0435\u0441\u0443\u0440\u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438:<\/p>\n<pre><code class=\"cpp\">\/\/ in \"co_chrono.\u0441pp\"  #include &lt;chrono> #include &lt;tuple>  struct PlatformClock{   using duration = std::chrono::duration&lt;base_t, std::milli>;   using rep = duration::rep;   using period =  duration::period;   using time_point = std::chrono::time_point&lt;PlatformClock, duration>;      static constexpr bool is_steady = false;      static time_point now() {     \/\/ \u043f\u0440\u0438\u043c\u0435\u0440 \u043a \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0430 stm-\u043a\u0435,     \/\/ \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u043d\u0435 \u043c\u0443\u0434\u0440\u0441\u0442\u0432\u0443\u044f \u043b\u0443\u043a\u0430\u0432\u043e, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0445\u0430\u043b\u043e\u0432\u0441\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439     auto millisecond_tick = HAL_GetTick();          return time_point(duration(millisecond_tick));   } };<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 CoChrono:<\/p>\n<pre><code class=\"cpp\">\/\/ in \"co_chrono.hpp\"  struct CoChrono{   \/\/ \u0437\u0430\u0432\u043e\u0434\u0438\u043c \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0442\u0430\u0439\u043c\u0435\u0440   static void set_timer (co_act_t A, base_t delay);   \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u044b   static void check_if_expired(); };  \/\/ in \"co_chrono.cpp\"  #include &lt;chrono> #include &lt;tuple> #include \"co_proxy.hpp\" #include \"co_queue_impl.hpp\" #include \"co_chrono.hpp\"  using namespace std::chrono;  \/\/ \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u0441\u044f \u043e\u0442 CoProxy, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \/\/ \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0442\u044c \u043e \u043d\u0430\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 class CoChronoImpl final: public CoProxy&lt;CoChronoImpl>{   public:   co_act_t give_impl(co_act_t A) { return A; } };  using co_chrono_t = CoProxy&lt;CoChronoImpl>;  \/\/ \u0437\u0430\u0434\u0430\u0435\u043c \u0442\u0438\u043f \u0438 \u0443\u0434\u043e\u0431\u043e\u0432\u0430\u0440\u0438\u043c\u044b\u0439 \u0430\u043b\u0438\u0430\u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430. \/\/ \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c id \u0442\u0430\u0439\u043c\u0435\u0440\u0430, \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0438 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 using chrono_entry_t = std::tuple&lt;co_act_t, PlatformClock::time_point, base_t>;  \/\/ \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438 \u0431\u0443\u0434\u0435\u043c \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438; \u0437\u0430\u0434\u0430\u0435\u043c \u0435\u0435 \u0442\u0438\u043f \u0438 \u0430\u043b\u0438\u0430\u0441 using chrono_queue_t =    CoQueueImpl&lt;chrono_entry_t, CoParam::CORO_TIMER_NUM, co_critical_t>;  \/\/ \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u0443\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u044c chrono_queue_t chrono_queue;   void CoChrono::set_timer (co_act_t A, base_t delay) {   \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438   chrono_queue.push( {A, PlatformClock::now(), delay} ); }  \/\/ \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \/\/ \u0442\u0430\u0439\u043c\u0435\u0440\u0430, \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0432 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 void CoChrono::check_if_expired() {   auto&amp; q = chrono_queue.get_instance();   co_chrono_t chrono;      \/\/ \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438   for (auto&amp; [act, start_point, delay] : q){          \/\/ \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430, \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e     if (not delay) continue;          \/\/ \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430     auto res =        duration_cast&lt;milliseconds>(PlatformClock::now() - start_point).count();          \/\/ \u0435\u0441\u043b\u0438 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u0448\u043b\u043e, \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u043c \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0443 \u0438 \u0437\u0430\u0447\u0438\u0449\u0430\u0435\u043c \u043f\u043e\u043b\u0435 delay,     \/\/ \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f     if (res > delay) {              chrono.give(act);              delay = 0;     }   } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0434\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 CoTimer:<\/p>\n<pre><code class=\"cpp\">\/\/ in \"co_timer.hpp\"  #include \"co_proxy.hpp\" #include \"co_chrono.hpp\"  template&lt;co_act_t A> class CoTimer final : public CoChrono, public CoProxy&lt;CoTimer&lt;A>>{   public:      template&lt;CoPrio P>   co_proxy_t&lt;A, P> get_impl(base_t delay) {     \/\/ \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0430\u0439\u043c\u0435\u0440     set_timer(A, delay);     return {};   } };  #define CO_TIMER(n)   using n = CoProxy&lt;CoTimer&lt;__COUNTER__>>  \/*  USER SECTION START  *\/ CO_TIMER(app_timer_t); \/*  USER SECTION END  *\/<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 CoEvent \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443, \u043e\u043d \u043d\u0435 \u043d\u0435\u0441\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u043a \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u043e\u043c\u0443. \u0415\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440 \u043d\u0430\u0448\u0435\u0439 \u041e\u0421  &#8212; \u043a\u043b\u0430\u0441\u0441 CoManager \u0438 \u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/p>\n<pre><code class=\"cpp\">\/\/ in \"co_manager.hpp\"  struct CoManager{     static void set_action(co_act_t act);     static void store_sync(co_sync_t s);     static void run(); };  \/\/ in \"co_manager.cpp\"  #include &lt;coroutine>  #include \"critical_section.hpp\" #include \"co_queue_impl.hpp\" #include \"co_manager.hpp\"  \/\/ \u0435\u0441\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0449\u0435\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u044d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b \u043e\u0442 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430, \/\/ \u0442\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430, \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 CoSync \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \/\/ \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 mutex_take() static bool mutex_take (co_sync_t sync); \/\/\u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0437\u0430 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b static void co_resume (co_sync_t sync);  \/\/ \u043d\u0430 \u0431\u0430\u0437\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0435\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u044c \/\/ \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043e\u0431\u044a\u0435\u043a\u0442\u044b \/\/ \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043a \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d using sync_queue_t =    CoQueueImpl&lt;co_sync_t, CoParam::CORO_TASK_NUM, co_critical_t>;  \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432\u0441\u0435\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b co_sync_t co_repo[CoParam::CORO_TASK_NUM];  \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \/\/ \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0445 \u0441\u0438\u0433\u043d\u0430\u043b \u043a \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044e. \/\/ \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u043e\u043e\u0442\u0432\u0442\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u0438\u0432\u044b\u0441\u0448\u0435\u043c\u0443 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0443 sync_queue_t co_queue_repo[CoPrio::num];  \/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0439 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 co_sync_t current; \/\/ \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u0434\u043b\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d base_t current_memory;   void CoManager::set_action(co_act_t act) {      \/\/ \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043e\u0431\u044a\u0435\u043a\u0442\u044b   for (auto sync : co_repo){     \/\/ \u0435\u0441\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0441 \u0442\u0430\u043a\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 -      \/\/ \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e     if (not sync) continue;     \/\/ \u0435\u0441\u043b\u0438 id \u043d\u0430\u0441\u0442\u0443\u043f\u0438\u0432\u0448\u0435\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 id \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e     \/\/ \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0442\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043a \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044e     \/\/ \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u044e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c     if(act == sync->expected)       co_queue_repo[sync->prio].push(sync);   } };  \/\/ \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 co_yield() \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \/\/ \u043d\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b void CoManager::store_sync(co_sync_t s) {   co_repo[s->id] = s; }  void CoManager::run(){      \/\/ \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e   \/\/ \u043a\u043e\u0440\u0443\u0442\u0438\u043d   for (auto&amp; queue : co_queue_repo){          \/\/ \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u043e\u043a\u0430 \u043e\u043d\u0430 \u043d\u0435 \u043e\u043f\u0443\u0441\u0442\u0435\u0435\u0442      while ( not queue.is_empty() ) {              co_sync_t sync = queue.back();              \/\/ \u0435\u0441\u043b\u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d       \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e current       \/\/ \u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443       if ( not current ||            CoState::suspended == current->state ){                 current = sync;                  co_resume(current);               \/\/ \u0435\u0441\u043b\u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430       \/\/ \u0438 \u0435\u0435 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043d\u0438\u0436\u0435, \u0447\u0435\u043c \u0443 \u0434\u0430\u043d\u043d\u043e\u0439, \u0442\u043e \u0432\u044b\u0442\u0435\u0441\u043d\u044f\u0435\u043c \u0435\u0435,       \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0432 \u0435\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e preemted.       \/\/ \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u0431\u043e\u043b\u0435\u0435 \u0441\u0440\u043e\u0447\u043d\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435       \/\/ \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u043d\u043e\u0439       } else if (CoState::running == current->state  &amp;&amp;                  sync->prio &lt; current->prio          ){                  current->state = CoState::blocked;         co_sync_t preemted = current;         current = sync;                  co_resume(current);                  preemted->state = CoState::running;         current = preemted;                } else {         return;       }     }   } }  static void co_resume (co_sync_t sync){   \/\/ \u0435\u0441\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0436\u0434\u0430\u043b\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u043e\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b,   \/\/ \u043d\u043e \u043e\u043d \u043f\u043e\u043a\u0430 \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d, \u0442\u043e \u043d\u0435 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u0441\u044f   if( not mutex_take(sync) ) return;       \/\/ \u043c\u0435\u043d\u044f\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0430 \"\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f\"   sync->state = CoState::running;   \/\/ \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c id \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f   sync->expected = std::numeric_limits&lt;co_act_t>::max();      \/\/ \u0432 \u043f\u0435\u0440\u0438\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 CoManager::run() \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f   \/\/ \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043c\u044b \u0438\u0445 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c   \/\/ (\u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043c\u043e\u0433\u043b\u0430 \u0431\u044b\u0442\u044c \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u043e\u0439)...   co_detail::enable_irq();      std::coroutine_handle&lt;>::from_address(sync->co_addr).resume();       \/\/ ... \u0430 \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 - \u0432\u043d\u043e\u0432\u044c \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c   co_detail::disable_irq(); }  static bool mutex_take (co_sync_t sync){      bool *mutex_ptr = sync->mutex.ptr;   \/\/ \u0435\u0441\u043b\u0438 mutex_ptr != nullptr \u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d   \/\/ \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443 \u043d\u0435 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c   if ( mutex_ptr &amp;&amp; (*mutex_ptr) ) return false;   \/\/ \u0438\u043d\u0430\u0447\u0435 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c   if (mutex_ptr) *mutex_ptr = true;      return true; } <\/code><\/pre>\n<p>\u041d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 arm cortex-m. \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u043a\u0440\u044b\u043b \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/506414\/\" rel=\"noopener noreferrer nofollow\">\u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b<\/a> \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u043e\u0433\u043e <a class=\"mention\" href=\"\/users\/lamerok\">@lamerok<\/a>. \u042f \u0441\u0430\u043c \u043f\u043e \u043d\u0435\u0439 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u043b \u0431\u0435\u043b\u044b\u0435 \u043f\u044f\u0442\u043d\u0430 \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438 \u0442\u0435\u043c\u044b<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442\u0435\u0441\u044c \u0432 \u044d\u0442\u043e\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0435, \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0440\u043e\u0448\u0442\u0443\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e.<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0443\u0441\u044c \u0441\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043f\u0440\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0438\u0437\u043c\u0443 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u041e\u0421:<\/p>\n<ol>\n<li>\n<p>\u0432 \u041c\u041a \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u043c \u0442\u0430\u0439\u043c\u0435\u0440 &#8212; \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0442\u0438\u043a\u043e\u0432 \u0434\u043b\u044f \u041e\u0421 (\u043e\u0431\u044b\u0447\u043d\u043e 1 \u0438\u043b\u0438 10 \u043c\u0441)<\/p>\n<\/li>\n<li>\n<p>\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u0439 \u044d\u0442\u043e\u0433\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u043c PendSV request<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 PendSV IRQ, \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0432 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u0438  \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0432 \u043d\u0430 \u0441\u0442\u0435\u043a\u0435 &#171;\u0441\u043d\u0438\u043c\u043e\u043a&#187; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0432 thread mode  \u043c\u0435\u0442\u043e\u0434 CoManager::run()<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 CoManager::run() \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c, \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u041e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u043d\u043e\u0432\u044c \u043f\u0440\u0435\u0440\u0432\u0430\u043d\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u043c \u0438 \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e \u043c\u0435\u0442\u043e\u0434\u0443 \u043c\u0430\u0442\u0440\u0435\u0448\u043a\u0438 \u0432\u043d\u043e\u0432\u044c \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043f.1 &#8212; 4.<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 CoManager::run()  \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e ManagerReturn() \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c NMI request.<\/p>\n<\/li>\n<li>\n<p>\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 NMI IRQ \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0434\u0440 \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432 thread mode<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u0443 \u0447\u0442\u043e \u0436, \u0432\u0441\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0438 \u0442\u0435\u043e\u0440\u0438\u044f \u043f\u043e\u0437\u0430\u0434\u0438, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c. \u041e\u043d\u043b\u0430\u0439\u043d \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c<a href=\"https:\/\/godbolt.org\/z\/xx9163bb9\" rel=\"noopener noreferrer nofollow\"> \u0437\u0434\u0435\u0441\u044c<\/a>. \u041d\u0430 \u0442\u0440\u0435\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043f\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432\u0441\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e-\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445 \u0441\u0434\u0435\u043b\u0430\u043b \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0438\u0437 \u043a\u043e\u0440\u0443\u0442\u0438\u043d; \u043c\u043e\u0436\u043d\u043e  \u043f\u043e\u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043f\u0440\u0438 \u0438\u0445 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435\/\u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438. \u041a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u0443\u0442\u043e\u0447\u043d\u0438\u0442\u044c \u0438\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<p>\u0420\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 STM32F412 Discovery \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u0440\u0430\u0442\u044c <a href=\"https:\/\/github.com\/ALSCode\/CoroOS\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>. \u0422\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u043d \u0430\u043a\u0446\u0435\u043d\u0442 \u043d\u0430 \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u044b\u043c\u0438. task_1 \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u0442 \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 event \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f TIM14, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 one pulse mode. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 event, task_1 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0438 \u0447\u0435\u0440\u0435\u0437 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c task_2. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0441\u0438\u0433\u043d\u0430\u043b \u043e\u0442 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, task_2 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0438 \u0432\u044b\u0442\u0435\u0441\u043d\u044f\u0435\u0442 task_1, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u043c\u0435\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u0438\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442. \u0422\u0430\u043a\u0436\u0435 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0432 \u043e\u0434\u043d\u0443 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, task_2 \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c task_3. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u043f\u043e \u0441\u0445\u043e\u0436\u0435\u043c\u0443 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044e \u0432\u044b\u0442\u0435\u0441\u043d\u044f\u0435\u0442 task_2. \u041f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u044b task_3, \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f task_2, \u0430 \u0441\u043b\u0435\u0434\u043e\u043c \u0438 task_1. \u0412 \u043a\u043e\u043d\u0446\u0435 task_1 \u0440\u0435\u0441\u0442\u0430\u0440\u0442\u0443\u0435\u0442 TIM14 \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f. \u0420\u0430\u0431\u043e\u0442\u0430 \u0437\u0430\u0434\u0430\u0447 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u044b \u0438 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 SWO.<\/p>\n<p>\u0418 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0432 \u0432 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u043f\u0438\u0441\u0430\u043d \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0442 \u041e\u0421 \u043d\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445. \u041e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u043f\u043e\u043a\u0430 \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043d \u043d\u0430 \u0441\u0430\u043c\u044b\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445. \u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u043a\u0430\u0442\u043a\u0430 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445, \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u044f \u0447\u0442\u043e-\u0442\u043e \u0437\u0435\u0432\u043d\u0443\u043b \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043a\u043e\u0434\u0430. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u043b\u043e\u0433\u0438\u043a\u0430 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430 \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u0430\u043c\u0430\u044f \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u0430\u044f, \u0442\u043e\u0447\u043d\u043e \u043f\u043e \u0445\u043e\u0434\u0443 \u0442\u0435\u0441\u0442\u043e\u0432 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0442\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c\u0441\u044f. \u0411\u0443\u0434\u0443 \u043f\u043e\u0442\u0438\u0445\u043e\u043d\u044c\u043a\u0443 \u0434\u043e\u043f\u0438\u043b\u0438\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0435 \u043e\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434, \u0435\u0441\u043b\u0438 \u0438\u0434\u0435\u0438 \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u0430\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u043d\u0435\u0431\u0435\u0437\u044b\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438.<\/p>\n<p>\u041a\u0430\u043a \u0438 \u0432\u0441\u0435\u0433\u0434\u0430, \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u043a\u0440\u0438\u0442\u0438\u043a\u0443 \u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u043d\u044b\u0435 \u0438\u0434\u0435\u0438.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/587000\/\"> https:\/\/habr.com\/ru\/articles\/587000\/<\/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<p>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440, \u0438 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u043c \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432.<\/p>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043b\u044e\u0431\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u043e\u0434\u0443\u043c\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043e\u0441\u044c. \u0414\u0430 \u0442\u0430\u043a\u0443\u044e, \u0447\u0442\u043e\u0431\u044b \u0434\u0440\u0443\u0433\u0438\u043c \u043d\u0435\u043f\u043e\u0432\u0430\u0434\u043d\u043e \u0431\u044b\u043b\u043e!<\/p>\n<p>\u0418 \u0432\u0430\u0448 \u0430\u0432\u0442\u043e\u0440 \u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. <\/p>\n<p>\u041a\u0430\u043a \u043f\u043e \u043c\u043d\u0435 &#8212; \u0434\u0435\u043b\u043e \u043d\u0435 \u0442\u043e \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u0435\u0434\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0435, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0440\u043e\u043f\u043e\u0442\u043b\u0438\u0432\u043e\u0435. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441, \u043a\u0430\u043a \u0438 \u0443 \u043c\u0435\u043d\u044f, \u0443\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043a\u0430\u0440\u044c\u0435\u0440\u0430 \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f \u0432\u043e\u043a\u0440\u0443\u0433 Arm Cortex-M \u0441\u0435\u0440\u0438\u0438, \u0442\u043e \u0432\u043e\u043e\u0440\u0443\u0436\u0430\u0435\u043c\u0441\u044f \u0441\u0442\u0432\u043e\u043b\u0430\u043c\u0438 (<a href=\"https:\/\/www.amazon.com\/Definitive-Guide-Cortex%C2%AE-M3-Cortex%C2%AE-M4-Processors\/dp\/0124080820\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0437<\/a>, <a href=\"https:\/\/www.amazon.com\/Designers-Guide-Cortex-M-Processor-Family\/dp\/0081006292\/ref=pd_bxgy_1\/142-2669340-8725063?pd_rd_w=FuhFp&amp;pf_rd_p=c64372fa-c41c-422e-990d-9e034f73989b&amp;pf_rd_r=S5PTR4Z07FP5KDD7ESQN&amp;pd_rd_r=2a860679-0d9d-4aef-a532-19e1b6de649b&amp;pd_rd_wg=xprvE&amp;pd_rd_i=0081006292&amp;psc=1\" rel=\"noopener noreferrer nofollow\">\u0434\u0432\u0430<\/a> \u0438 <a href=\"https:\/\/developer.arm.com\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0440\u0438<\/a>) \u0438 \u0432\u044b\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0437\u0430 <a href=\"https:\/\/aws.amazon.com\/ru\/freertos\/\" rel=\"noopener noreferrer nofollow\">\u0414\u0436\u0435\u0444\u0444\u043e\u043c<\/a>. <\/p>\n<p>\u041d\u043e, \u043d\u0430\u043f\u0438\u0441\u0430\u0432  \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u044f\u0434\u0440\u043e \u0441\u0432\u043e\u0435\u0439 &#171;best of the best&#187; \u043e\u0441\u0438 \u043e\u043a\u043e\u043b\u043e \u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434, \u044f \u0432\u0441\u043a\u043e\u0440\u0435 \u0437\u0430\u0431\u0440\u043e\u0441\u0438\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443. \u0418\u0431\u043e \u043a\u0430\u043a \u044f \u043d\u0438 \u043a\u0440\u0435\u0430\u0442\u0438\u0432\u0438\u043b, \u0432\u043c\u0435\u0441\u0442\u043e \u0421\u043e\u043a\u043e\u043b\u0430 \u0422\u044b\u0441\u044f\u0447\u0435\u043b\u0435\u0442\u0438\u044f \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0441\u044f \u043a\u0440\u0435\u043f\u0435\u043d\u044c\u043a\u0438\u0439, \u043d\u043e \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0438 \u0441\u043a\u0443\u0447\u043d\u044b\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434.<\/p>\n<p>\u0410 \u0432\u0435\u0434\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0431\u0435\u0441\u0441\u0442\u044b\u0434\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u0435\u043d\u0434\u0440\u0451\u0436\u0430.<\/p>\n<p>\u0418 \u0442\u0443\u0442 \u0432 20-\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u0437\u0430\u0432\u0435\u0437\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. <\/p>\n<p>\u0412\u043e\u0442 \u044d\u0442\u043e \u0432\u043e\u0442 \u0432\u0441\u0451:<\/p>\n<pre><code class=\"cpp\">#include &lt;coroutine>  Coro task(){      foo();      co_await awaitable_1();      bar();      auto res = co_await awaitable_2();      func(res);  }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0430\u0448\u0430 \u0447\u0443\u0439\u043a\u0430 \u044d\u043c\u0431\u0435\u0434\u0434\u0435\u0440\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u043d\u0443\u0442\u044c: &#171;\u0410 \u0435\u0441\u043b\u0438 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u043d\u043e \u0441 \u043f\u0435\u0440\u043b\u0430\u043c\u0443\u0442\u0440\u043e\u0432\u044b\u043c\u0438 \u043f\u0443\u0433\u043e\u0432\u0438\u0446\u0430\u043c\u0438?&#187; :<\/p>\n<pre><code class=\"cpp\">#include &lt;coroutine>  Coro task1() {    while (true) {     \/\/ \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043d\u0435\u043a\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435     co_await event.get();     \/\/ \u043f\u043e \u0435\u0433\u043e \u043d\u0430\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044e \u0431\u043b\u0438\u043d\u043a\u0430\u0435\u043c     toggle_led();     \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0430\u0439\u043c\u0435\u0440 \u043d\u0430 250 \u043c\u0441\/\u0441\/\u043c\u0438\u043d \u0438 \u0436\u0434\u0435\u043c     co_await timer.get(250);     \/\/ \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u0441\u043d\u043e\u0432\u0430 \u0431\u043b\u0438\u043d\u043a\u0430\u0435\u043c     toggle_led();     \/\/ \u0438 \u0432\u0441\u0435 \u043f\u043e \u043d\u043e\u0432\u043e\u0439    } }<\/code><\/pre>\n<p>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0442\u0438\u043f\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u0420\u0422\u041e\u0421. \u041f\u0440\u0438\u0447\u0435\u043c \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u043e\u0437\u044c\u043c\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0440\u0430\u0441\u0447\u0435\u0442 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0434 \u0437\u0430\u0434\u0430\u0447\u0443. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u0443\u0447\u0435\u0441\u0442\u044c. \u041d\u0430\u043c \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u0438, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e \u043f\u043e\u0434 \u0432\u0441\u0435 \u0437\u0430\u0434\u0430\u0447\u0438. \u0423\u0436\u0435 \u043d\u0435\u043f\u043b\u043e\u0445\u043e. <\/p>\n<p>\u0424\u0430\u043d\u0442\u0430\u0437\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435. \u0411\u0443\u0434\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u043e, \u0435\u0441\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 co_await \u0441\u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u0435\u0434\u0438\u043d\u044b\u043c \u043e\u043a\u043d\u043e\u043c \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439, \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u043e\u043c \u0438 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430\u043c\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 (\u044d\u0432\u0435\u043d\u0442\u044b, \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b, \u0442\u0430\u0439\u043c\u0435\u0440\u044b, \u043e\u0447\u0435\u0440\u0435\u0434\u0438 etc.). \u0422\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c  \u0432\u044b\u0438\u0433\u0440\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430. <\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e, \u0430 \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430\u043c\u0438 \u0437\u0430\u0434\u0430\u0447? \u0410 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u0440\u0437\u043d\u0443\u0442\u044c, \u0432\u044b\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0435 \u043d\u0430\u0438\u0437\u043d\u0430\u043d\u043a\u0443 \u0438 \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0441 <em>\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c<\/em> \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f :<\/p>\n<pre><code class=\"cpp\">#include &lt;coroutine>  Coro task2(){      while(true){     \/\/ \u0436\u0434\u0435\u043c \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u043e\u0442 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c     co_await queue.get&lt;CoPrio::normal>();     \/\/ \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430     auto payload = queue.unload();     \/\/ \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u043c\u044e\u0442\u0435\u043a\u0441. \u0415\u0441\u043b\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c     \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441\u0440\u0430\u0437\u0443. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442 - \u0436\u0434\u0435\u043c \u0435\u0433\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f      co_await mutex.get&lt;CoPrio::low>();     \/\/ \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043d\u0435\u043a\u0438\u043c \u043e\u0431\u0449\u0438\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043d\u0438\u0437\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430     shared_bus_send(res);     \/\/ \u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441     mutex.give();     \/\/ \u0436\u0434\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0441 \u0432\u044b\u0441\u043e\u043a\u0438\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c     co_await event.get&lt;CoPrio::high>();     \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u0440\u043e\u0447\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430     very_urgent_func();   } }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0437\u0430\u043c\u0430\u043d\u0447\u0438\u0432\u043e.<\/p>\n<p>\u041e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043d\u0430\u0432\u0435\u0441\u0438\u0442\u044c \u0441\u044e\u0434\u0430 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440, \u0436\u043e\u043d\u0433\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043d\u0430\u0448\u0438\u043c\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438, \u043f\u043b\u044e\u0441 context switcher, \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u0447\u0442\u043e \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e\u0435. \u041f\u043e\u0445\u043e\u0436\u0435, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u0443 \u0438 \u0445\u0430\u0439\u043f\u0430\u043d\u0443\u0442\u044c \u043d\u0430 \u0433\u043e\u0440\u044f\u0447\u0435\u043d\u044c\u043a\u043e\u0439 \u0435\u0449\u0435 \u0442\u0435\u043c\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d &#8212; \u043a\u0430\u043a \u0436\u0435 \u0431\u0435\u0437 \u044d\u0442\u043e\u0433\u043e \ud83d\ude42<\/p>\n<p>\u0414\u043b\u044f \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u043e\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u0430\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0432\u043e\u0434\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u0435\u0435 \u043f\u043e \u0445\u043e\u0434\u0443 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<ul>\n<li>\n<p>\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0447\u0442\u043e \u0432\u044b \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043a \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044e \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e <a href=\"https:\/\/habr.com\/ru\/company\/yandex\/blog\/420861\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a>. \u0422\u0430\u043a\u0436\u0435 \u0437\u0430\u0431\u0443\u0440\u0438\u0442\u044c\u0441\u044f \u0432 \u0442\u0435\u043c\u0443 \u043f\u043e\u0433\u043b\u0443\u0431\u0436\u0435 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/habr.com\/ru\/company\/wunderfund\/blog\/582000\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441 \u043a\u043e\u0434\u043e\u043c \u0438 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u0430\u043c \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044f, \u044f \u0431\u0443\u0434\u0443 \u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043a\u0432\u0430\u043b\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0438\u0437 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\/\u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0440\u0430\u0431\u043e\u0447\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044f \u0434\u0430\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438. <\/p>\n<\/li>\n<li>\n<p>\u0432\u0430\u0436\u043d\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u0441\u0442\u0430\u0442\u044c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043a\u043e\u0434\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043b\u0435\u0435 &#8212; \u0432\u0434\u0443\u043c\u0447\u0438\u0432\u044b\u0439 \u043b\u043e\u043d\u0433\u0440\u0438\u0434. \u0412\u0441\u0435-\u0442\u0430\u043a\u0438 \u043e\u0441\u044c \u043f\u0438\u0448\u0435\u043c, \u0430 \u043d\u0435 \u043c\u043e\u0440\u0433\u0430\u043b\u043a\u0443 \u0430\u0440\u0434\u0443\u0438\u043d\u043e\u0432\u0441\u043a\u0443\u044e.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e-\u043d\u0430\u043f\u0435\u0440\u0432\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0435\u043a\u0438\u0439 \u0441\u0438\u043d\u0445\u0440\u043e-\u043e\u0431\u044a\u0435\u043a\u0442, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439 \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043c\u0438\u0440\u043e\u043c. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"cpp\">#include \"co_types.hpp\"  struct CoSync{   co_mutex_t mutex;  \/\/ \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430      \/\/ \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0433\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043e CoMutex   void* co_addr;     \/\/ \u0430\u0434\u0440\u0435\u0441 coroutine_handle   CoState state;     \/\/ \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b (\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 etc.)   CoPrio prio;       \/\/ \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442   base_t id;         \/\/ \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440   base_t size;       \/\/ \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043f\u0430\u043c\u044f\u0442\u0438   co_act_t expected; \/\/ \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 };  \/\/ \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0430\u043b\u0438\u0430\u0441 \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 CoSync using co_sync_t = CoSync*;<\/code><\/pre>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0439; \u043c\u044b \u0432\u043e\u043b\u044c\u043d\u044b \u043f\u0440\u0438 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u043e\u0432\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 promise_type \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u043d\u0430\u0431\u043e\u0440  \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Promise \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/coroutines#co_await\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<pre><code class=\"cpp\">#include &lt;coroutine> #include &lt;limits>  #include \"co_proxy.hpp\" #include \"co_alloc.hpp\"  struct Coro {      using promise_type = Coro;      CoSync sync {     .mutex{.ptr = nullptr, .is_taken = false},     .co_addr{nullptr},     .state{CoState::stopped},     .prio{CoPrio::lowest},     .id{ indexer_t{}() }, \/\/ \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 id     \/\/ \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b     .size{0},     .expected{std::numeric_limits&lt;co_act_t>::max()},   };      auto get_return_object() { return Coro{}; }      std::suspend_never initial_suspend() {     \/\/ \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430,     \/\/ \u043c\u0435\u043d\u044f\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0430 \"\u0433\u043e\u0442\u043e\u0432\u0430\"     sync.state = CoState::ready;     \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u043f\u0430\u043c\u044f\u0442\u0438     sync.size = CoAlloc::get_current_size();     return {};   }      template&lt;co_act_t ID, CoPrio P>   auto yield_value ( co_proxy_t&lt;ID, P> p) {          struct Awaitable{ \/* \u0441\u043c. \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0438\u0436\u0435 *\/ };          return Awaitable{p}; }      template&lt;co_act_t ID, CoPrio P>   auto await_transform(co_proxy_t&lt;ID, P> p) {     return yield_value&lt;ID, P>(p);   }      void* operator new(std::size_t sz){     \/\/ \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u043b\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439     \/\/ \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 new, \u0441\u0442\u043e\u0431\u044b \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c     \/\/ \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u043c. \u041a\u0430\u043a \u0438 \u0433\u0434\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c.     return CoAlloc::allocate(sz); }  void operator delete( void* p){     CoAlloc::deallocate(p);   } }; <\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0435\u0436\u0438\u043c\u0441\u044f \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437 \u0438 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u0432 promise_type.<\/p>\n<p>\u0412 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043c\u044b \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0435\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440. \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0438\u0441\u043b\u043e \u043e\u0442 0 \u0434\u043e \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u0434\u0430\u0447, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435. \u0415\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435  &#8212; \u0441\u043b\u0443\u0436\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0441\u0438\u043d\u0445\u0440\u043e-\u043e\u0431\u044a\u0435\u043a\u0442\u044b CoSync. \u0418\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u043c\u044b \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0442\u0438\u043f\u0430 indexer_t :<\/p>\n<pre><code class=\"cpp\">using indexer_t = decltype( []{ static base_t i; return ++i - 1; } );<\/code><\/pre>\n<p>\u0418\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0441\u0442\u0432\u043e? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0435\u0434\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u041d\u043e \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435\u0437\u0434\u043e\u0440\u041e\u0432\u043e \u0444\u0430\u043d\u0430\u0442\u0435\u044e \u043f\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044e \u043b\u043e\u0433\u0438\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u0442\u0438\u043f\u044b. \u0422\u0438\u043f\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043c\u0435\u0441\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0435 \u0437\u0430\u043c\u0443\u0441\u043e\u0440\u0438\u0432\u0430\u044f \u043a\u043e\u0434 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438. \u0422\u0438\u043f\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0445\u0430\u0442\u044c \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u044b, \u043f\u043e\u043c\u043e\u0433\u0430\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c \u043a\u043e\u0434, \u043f\u0435\u0440\u0435\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 \u043a\u043e\u043c\u043f\u0430\u0439\u043b \u0442\u0430\u0439\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0442\u0435\u0440\u043f\u0438\u0442\u0435 \u0447\u0443\u0442\u043a\u0430:)<\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 Awaitable:<\/p>\n<pre><code class=\"cpp\">#include &lt;coroutine>  struct Awaitable{   \/\/ \u043e\u0431\u044a\u0435\u043a\u0442 proxy \u043f\u0440\u0438 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 Awaitable \u0432   \/\/ \u043c\u0435\u0442\u043e\u0434\u0435 yield_value \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 p,   \/\/ \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 (\u044d\u0432\u0435\u043d\u0442, \u043e\u0447\u0435\u0440\u0435\u0434\u044c etc.).   \/\/ proxy - \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 co_proxy_t(\u0441\u043c. \u043d\u0438\u0436\u0435),    \/\/ \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c   \/\/ \u043e\u043d \u0441\u043b\u0443\u0436\u0438\u0442 \u043a\u0430\u043d\u0430\u043b\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u043d\u0444\u043e \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438   \/\/ \u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439.   co_proxy_t&lt;ID, P> proxy;      \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 proxy \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430.   \/\/ \u043f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443 \u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c   \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438   bool await_ready () {     \/\/ \u0435\u0441\u043b\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u043b\u0441\u044f - \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e     \/\/ \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u0441\u044f.     if (not proxy.mutex.ptr) return false;          \/\/ \u0438\u043d\u0430\u0447\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0444\u043b\u0430\u0433 \u0437\u0430\u0445\u0432\u0430\u0442\u0430 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u043c \u043f\u043e     \/\/ \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e     return proxy.mutex.is_taken;   }      void await_suspend (std::coroutine_handle&lt;promise_type> coro) {     \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u043f\u043e\u043b\u044f sync \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 promise \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b      co_sync_t sync = &amp;coro.promise().sync;          \/\/ \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 co_await \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c     \/\/ \u043d\u0430 sync \u0432 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0435. co_proxy_t \u0437\u043d\u0430\u0435\u0442 \u043e \u0442\u0438\u043f\u0435     \/\/ \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c     \/\/ \u043c\u0435\u0442\u043e\u0434\u0430\u043c     if (CoState::ready == sync->state)                     decltype(proxy)::store_sync(sync);          \/\/ \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 sync: \u0430\u0434\u0440\u0435\u0441 cooutine_handle,     \/\/ \u043d\u043e\u0432\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430, \u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435.     \/\/ \u0442\u0430\u043a\u0436\u0435 \u043c\u0435\u043d\u044f\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043d\u0430 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0435      sync->co_addr = coro.address();     sync->mutex = proxy.mutex;     sync->state = CoState::suspended;     sync->prio = P;     sync->expected = ID;   }      \/\/ \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043e\u0441\u0438 \u044f \u043f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0443\u0436\u043d\u043e   \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 co_yield, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u043a\u0430 0   auto await_resume () { return 0; } }; <\/code><\/pre>\n<p>\u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u044e\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0432 \u043a\u0443\u0447\u0435. \u0414\u043b\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u043b\u043e\u0432\u043e &#171;\u043a\u0443\u0447\u0430&#187; \u043f\u043e\u0447\u0442\u0438 \u0440\u0443\u0433\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e. \u0425\u043e\u0440\u043e\u0448\u0438\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u041f\u041e, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0441\u0430\u043c \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043c\u0443, \u0433\u0434\u0435 \u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438. \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0431\u044b\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u043c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440. \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430 \u0438 \u0437\u0430\u044e\u0437\u0430\u0435\u043c std::pmr::monotonic_buffer_resource. \u041e\u043d \u0431\u044b\u0441\u0442\u0440\u044b\u0439, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b (de)allocate() : <\/p>\n<pre><code class=\"cpp\">\/\/ in co_alloc.cpp  #include &lt;memory_resource> #include \"co_alloc.hpp\"  byte_t raw_buf[CoParam::CORO_STORAGE_SIZE];  std::pmr::monotonic_buffer_resource mbr{raw_buf, CoParam::CORO_STORAGE_SIZE};  \/\/ \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f current_size \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \/\/ \u043a\u043e\u043b-\u0432\u0430 \u0431\u0430\u0439\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438. \/\/ max_size - \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0432\u0441\u0435\u043c\u0438 \/\/ \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 std::size_t current_size, max_size;<\/code><\/pre>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f CoAlloc \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430(\u0432\u0442\u043e\u0440\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u043e\u043f\u0443\u0449\u0435\u043d\u044b):<\/p>\n<pre><code class=\"cpp\">\/\/ in co_alloc.hpp  struct CoAlloc{   static void* allocate (std::size_t<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-413583","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/413583","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=413583"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/413583\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=413583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=413583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=413583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}