{"id":883,"date":"2023-01-05T23:25:13","date_gmt":"2023-01-05T15:25:13","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=883"},"modified":"2023-01-05T23:25:13","modified_gmt":"2023-01-05T15:25:13","slug":"boost-asio-note-executors","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=883","title":{"rendered":"boost asio note &#8211;  Executors"},"content":{"rendered":"<blockquote>\n<p>Every asynchronous agent has an associated executor. An agent's executor determines how the agent's completion handlers are queued and ultimately run.<\/p>\n<\/blockquote>\n<p>\u6bcf\u4e2a\u5f02\u6b65\u4ee3\u7406\u90fd\u6709\u4e00\u4e2a\u5173\u8054\u7684\u6267\u884c\u5668\u3002 \u4ee3\u7406\u7684\u6267\u884c\u8005\u786e\u5b9a\u4ee3\u7406\u7684\u5b8c\u6210\u5904\u7406\u7a0b\u5e8f\u5982\u4f55\u6392\u961f\u5e76\u6700\u7ec8\u8fd0\u884c<\/p>\n<blockquote>\n<p>Example uses of executors include:<\/p>\n<p>Coordinating a group of asynchronous agents that operate on shared data structures, ensuring that the agents' completion handlers never run concurrently[5].<br \/>\nEnsuring that agents are run on specified execution resource (e.g. a CPU) that is proximal to data or an event source (e.g. a NIC).<br \/>\nDenoting a group of related agents, and so enabling dynamic thread pools to make smarter scheduling decisions (such as moving the agents between execution resources as a unit).<br \/>\nQueuing all completion handlers to run on a GUI application thread, so that they may safely update user interface elements.<br \/>\nReturning an asynchronous operation's default executor as-is, to run completion handlers as close as possible to the event that triggered the operation's completion.<br \/>\nAdapting an asynchronous operation's default executor, to run code before and after every completion handler, such as logging, user authorisation, or exception handling.<br \/>\nSpecifying a priority for an asynchronous agent and its completion handlers.<\/p>\n<\/blockquote>\n<p>\u6267\u884c\u8005\u7684\u793a\u4f8b\u7528\u9014\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u534f\u8c03\u4e00\u7ec4\u5728\u5171\u4eab\u6570\u636e\u7ed3\u6784\u4e0a\u8fd0\u884c\u7684\u5f02\u6b65\u4ee3\u7406\uff0c\u786e\u4fdd\u4ee3\u7406\u7684\u5b8c\u6210\u5904\u7406\u7a0b\u5e8f\u6c38\u8fdc\u4e0d\u4f1a\u540c\u65f6\u8fd0\u884c (boost asio \u4e2d\u79f0\u4e3a strand)\u3002<\/li>\n<li>\u786e\u4fdd\u4ee3\u7406\u5728\u6700\u63a5\u8fd1\u6570\u636e\u6216\u4e8b\u4ef6\u6e90\uff08\u4f8b\u5982 NIC\uff09\u7684\u6307\u5b9a\u6267\u884c\u8d44\u6e90\uff08\u4f8b\u5982 CPU\uff09\u4e0a\u8fd0\u884c\u3002<\/li>\n<li>\u8868\u793a\u4e00\u7ec4\u76f8\u5173\u7684\u4ee3\u7406\uff0c\u4ece\u800c\u4f7f\u52a8\u6001\u7ebf\u7a0b\u6c60\u80fd\u591f\u505a\u51fa\u66f4\u667a\u80fd\u7684\u8c03\u5ea6\u51b3\u7b56\uff08\u4f8b\u5982\u5c06\u4ee3\u7406\u4f5c\u4e3a\u4e00\u4e2a\u5355\u5143\u5728\u6267\u884c\u8d44\u6e90\u4e4b\u95f4\u79fb\u52a8\uff09\u3002<\/li>\n<li>\u5c06\u6240\u6709\u5b8c\u6210\u5904\u7406\u7a0b\u5e8f\u6392\u961f\u4ee5\u5728 GUI \u5e94\u7528\u7a0b\u5e8f\u7ebf\u7a0b\u4e0a\u8fd0\u884c\uff0c\u4ee5\u4fbf\u5b83\u4eec\u53ef\u4ee5\u5b89\u5168\u5730\u66f4\u65b0\u7528\u6237\u754c\u9762\u5143\u7d20\u3002<\/li>\n<li>\u6309\u539f\u6837\u8fd4\u56de\u5f02\u6b65\u64cd\u4f5c\u7684\u9ed8\u8ba4\u6267\u884c\u7a0b\u5e8f\uff0c\u4ee5\u5c3d\u53ef\u80fd\u63a5\u8fd1\u89e6\u53d1\u64cd\u4f5c\u5b8c\u6210\u7684\u4e8b\u4ef6\u8fd0\u884c\u5b8c\u6210\u5904\u7406\u7a0b\u5e8f\u3002<\/li>\n<li>\u8c03\u6574\u5f02\u6b65\u64cd\u4f5c\u7684\u9ed8\u8ba4\u6267\u884c\u7a0b\u5e8f\uff0c\u4ee5\u5728\u6bcf\u4e2a\u5b8c\u6210\u5904\u7406\u7a0b\u5e8f\u4e4b\u524d\u548c\u4e4b\u540e\u8fd0\u884c\u4ee3\u7801\uff0c\u4f8b\u5982\u65e5\u5fd7\u8bb0\u5f55\u3001\u7528\u6237\u6388\u6743\u6216\u5f02\u5e38\u5904\u7406\u3002<\/li>\n<li>\u6307\u5b9a\u5f02\u6b65\u4ee3\u7406\u53ca\u5176\u5b8c\u6210\u5904\u7406\u7a0b\u5e8f\u7684\u4f18\u5148\u7ea7\u3002<\/li>\n<\/ul>\n<blockquote>\n<p>The asynchronous operations within an asynchronous agent use the agent's associated executor to:<\/p>\n<p>Track the existence of the work that the asynchronous operation represents, while the operation is outstanding.<br \/>\nEnqueue the completion handler for execution on completion of an operation.<br \/>\nEnsure that completion handlers do not run re-entrantly, if doing so might lead to inadvertent recursion and stack overflow.<\/p>\n<p>Thus, an asynchronous agent's associated executor represents a policy of how, where, and when the agent should run, specified as a cross-cutting concern to the code that makes up the agent.<\/p>\n<\/blockquote>\n<p>\u5f02\u6b65\u4ee3\u7406\u4e2d\u7684\u5f02\u6b65\u64cd\u4f5c\u4f7f\u7528\u4ee3\u7406\u7684\u5173\u8054\u6267\u884c\u5668\u6765\uff1a<\/p>\n<ul>\n<li>\u8ddf\u8e2a\u5f02\u6b65\u64cd\u4f5c\u6240\u4ee3\u8868\u7684\u5de5\u4f5c\u662f\u5426\u5b58\u5728\uff0c\u800c\u64cd\u4f5c\u662f\u672a\u5b8c\u6210\u7684\u3002<\/li>\n<li>\u5c06\u5b8c\u6210\u5904\u7406\u7a0b\u5e8f\u52a0\u5165\u961f\u5217\u4ee5\u5728\u64cd\u4f5c\u5b8c\u6210\u65f6\u6267\u884c\u3002<\/li>\n<li>\u786e\u4fdd\u5b8c\u6210\u5904\u7406\u7a0b\u5e8f\u4e0d\u4f1a\u91cd\u65b0\u8fd0\u884c\uff0c\u5982\u679c\u8fd9\u6837\u505a\u53ef\u80fd\u4f1a\u5bfc\u81f4\u65e0\u610f\u7684\u9012\u5f52\u548c\u5806\u6808\u6ea2\u51fa\u3002<\/li>\n<\/ul>\n<p>\u56e0\u6b64\uff0c\u5f02\u6b65\u4ee3\u7406\u7684\u5173\u8054\u6267\u884c\u5668\u8868\u793a\u4ee3\u7406\u5e94\u8be5\u5982\u4f55\u3001\u5728\u4f55\u5904\u4ee5\u53ca\u4f55\u65f6\u8fd0\u884c\u7684\u7b56\u7565\uff0c\u6307\u5b9a\u4e3a\u6784\u6210\u4ee3\u7406\u7684\u4ee3\u7801\u7684\u6a2a\u5207\u5173\u6ce8\u70b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every asynchronous agent has an associated executor. An agent&#8217;s executor determines how the agent&#8217;s completion handlers are queued and ultimately run. \u6bcf\u4e2a\u5f02\u6b65\u4ee3\u7406\u90fd\u6709\u4e00\u4e2a\u5173\u8054\u7684\u6267\u884c\u5668\u3002 \u4ee3\u7406\u7684\u6267\u884c\u8005\u786e\u5b9a\u4ee3\u7406\u7684\u5b8c\u6210\u5904\u7406\u7a0b\u5e8f\u5982\u4f55\u6392\u961f\u5e76\u6700\u7ec8\u8fd0\u884c Example uses of executors include: Coordinating a group of asynchronous agents that operate on shared data structures, ensuring that the agents&#8217; completion handlers never run concurrently[5]. Ensuring that agents are run on [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=883\" title=\"Permanent Link to: boost asio note &#8211;  Executors\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-883","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/883"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=883"}],"version-history":[{"count":1,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/883\/revisions"}],"predecessor-version":[{"id":884,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/883\/revisions\/884"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}