{"id":47025,"date":"2025-07-30T05:41:56","date_gmt":"2025-07-29T21:41:56","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/47025.html"},"modified":"2025-07-30T05:41:56","modified_gmt":"2025-07-29T21:41:56","slug":"%e3%80%90%e4%bb%bfmuduo%e5%ba%93%e5%ae%9e%e7%8e%b0%e5%b9%b6%e5%8f%91%e6%9c%8d%e5%8a%a1%e5%99%a8%e3%80%91loopthreadpool%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/47025.html","title":{"rendered":"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011LoopThreadPool\u6a21\u5757"},"content":{"rendered":"<\/p>\n<h4>\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668<\/h4>\n<ul>\n<li>1.LoopThread\u6a21\u5757<\/li>\n<li>\n<ul>\n<li>1.1\u6210\u5458\u53d8\u91cf<\/li>\n<li>1.2\u6784\u9020\u51fd\u6570<\/li>\n<li>13\u7ebf\u7a0b\u5165\u53e3\u51fd\u6570<\/li>\n<li>1.4\u83b7\u53d6eventloop\u5bf9\u8c61GetLoop()<\/li>\n<\/ul>\n<\/li>\n<li>2.LoopThreadPool\u6a21\u5757<\/li>\n<li>\n<ul>\n<li>2.1\u6210\u5458\u53d8\u91cf<\/li>\n<li>2.2\u6784\u9020\u51fd\u6570<\/li>\n<li>2.3\u914d\u7f6e\u7ebf\u7a0b\u6570\u91cf<\/li>\n<li>2.4\u6309\u7167\u914d\u7f6e\u6570\u91cf\u521b\u5efa\u7ebf\u7a0b<\/li>\n<li>2.5\u4f9d\u6b21\u5206\u914dEventloop\u5bf9\u8c61<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>1.LoopThread\u6a21\u5757<\/h2>\n<p>\u8fd9\u4e2a\u6a21\u5757\u662f\u4e3a\u4e86\u5c06EventLoop\u4e0e\u7ebf\u7a0b\u6574\u5408\u8d77\u6765\u3002\u4e00\u4e2aEventLoop\u5bf9\u5e94\u4e00\u4e2a\u7ebf\u7a0b\u3002 \u8981\u77e5\u9053EventLoop\u5bf9\u8c61\u5b9e\u4f8b\u5316\u65f6\u5c31\u4f1a\u5c06\u5b83\u7684thread_id\u7ed1\u5b9a&#xff0c;\u7136\u540e\u540e\u7eed\u7684RuninLoop\u64cd\u4f5c\u91cc\u9762\u5c31\u4f1a\u5224\u65ad\u5f53\u524d\u6267\u884c\u6d41\u7684\u7ebf\u7a0bid\u4e0eeventloop\u5bf9\u5e94\u7684\u7ebf\u7a0bid\u8fdb\u884c\u6bd4\u8f83&#xff0c;\u5982\u679c\u76f8\u540c\u5c31\u8bf4\u660e\u662f\u540c\u4e00\u4e2a\u7ebf\u7a0b&#xff0c;\u5982\u679c\u4e0d\u76f8\u540c&#xff0c;\u5c31\u8bf4\u660e\u4e0d\u662f\u540c\u4e00\u4e2a\u7ebf\u7a0b\u6267\u884c\u3002<\/p>\n<p>\u8fd9\u91cc\u8981\u6ce8\u610f\u7684\u662f&#xff1a; eventloop\u5bf9\u8c61\u7684\u5b9e\u4f8b\u5316\u5fc5\u987b\u5728\u7ebf\u7a0b\u521b\u5efa\u4e4b\u540e&#xff0c;\u4e5f\u5c31\u662f\u5728\u7ebf\u7a0b\u7684\u5165\u53e3\u51fd\u6570\u4e2d\u8fdb\u884c\u521b\u5efa&#xff0c;\u7136\u540eeventloop\u5bf9\u8c61\u4e00\u521b\u5efa\u51fa\u6765\u5c31\u7ed1\u5b9a\u8be5\u7ebf\u7a0b\u3002<\/p>\n<p>\u5c31\u662f\u6784\u9020\u4e00\u4e2a\u65b0\u7684\u6a21\u5757&#xff0c;\u5b83\u5728\u91cc\u8fb9\u65e2\u6709\u7ebf\u7a0b\u53c8\u6709eventloop&#xff0c;\u800c\u4e14\u5b83\u662f\u5148\u6709\u7ebf\u7a0b\u7136\u540e\u5728\u7ebf\u7a0b\u91cc\u8fb9\u518d\u53bb\u5b9e\u4f8b\u5316eventlop&#xff0c;\u8fd9\u6837\u5c31\u80fd\u591f\u4fdd\u8bc1eventloop\u5728\u51fa\u73b0\u7684\u7b2c\u4e00\u65f6\u523b\u5c31\u8ddf\u6211\u4eec\u7684\u4e00\u4e2a\u7ebf\u7a0b\u662f\u7ed1\u5b9a\u5230\u4e00\u8d77\u7684\u3002<\/p>\n<p>\u3010\u83b7\u53d6eventloop\u5bf9\u8c61\u3011 \u8fd9\u4e2a\u6a21\u5757&#xff0c;\u5b83\u5c06\u7ebf\u7a0b\u8ddfeventloop\u7ed9\u6574\u5408\u5230\u4e00\u8d77\u4e86&#xff0c;\u90a3\u4e48\u95ee\u9898\u5c31\u6765\u4e86&#xff0c;\u90a3\u5f53\u6211\u4eec\u5916\u754c\u8bf4\u4e00\u4e2a\u65b0\u8fde\u63a5\u5230\u6765\u4e86&#xff0c;\u73b0\u5728\u8981\u7ed9\u5b83\u5206\u914d\u4e00\u4e2aeventloop\u5bf9\u8c61&#xff0c;\u600e\u4e48\u7ed9\u5b83\u5206\u914d\u5462&#xff1f;\u6211\u603b\u5f97\u80fd\u591f\u83b7\u53d6\u5230\u8fd9\u4e2aevetloop\u5bf9\u8c61\u5427&#xff0c;\u6240\u4ee5\u5728\u8fd9\u4e2a\u91cc\u8fb9\u6211\u4eec\u9700\u8981\u63d0\u4f9b\u4e00\u4e2a\u63a5\u53e3\u53eb\u505aGetLoop&#xff0c;\u83b7\u53d6\u5230eventloop\u5bf9\u8c61\u7684\u6307\u9488\u3002 \u90a3\u4e48\u5f53\u5916\u754c\u53ef\u4ee5\u83b7\u53d6\u5230\u8fd9\u4e2aeventloop\u5bf9\u8c61\u6307\u9488\u4e4b\u540e&#xff0c;\u5f53\u65b0\u8fde\u63a5\u5230\u6765\u65f6&#xff0c;\u5c31\u53ef\u4ee5\u5c06\u8be5\u7ebf\u7a0b\u7684eventloop\u5206\u914d\u7ed9\u8be5\u7ebf\u7a0b&#xff0c;\u8be5\u8fde\u63a5\u5b83\u5c31\u7ed1\u5b9a\u5728\u8be5eventloop\u5bf9\u5e94\u7684\u7ebf\u7a0b\u4e0a\u5de5\u4f5c\u3002 \u6bd4\u5982\u5728\u6267\u884c\u5404\u79cd\u64cd\u4f5c\u7684\u65f6\u5019&#xff0c;\u8fdb\u884c\u4e8b\u4ef6\u76d1\u63a7\u7684\u65f6\u5019&#xff0c;\u5b83\u5c31\u4f1a\u7ed1\u5b9a\u5230\u6211\u4eeceventloop\u5bf9\u5e94\u7684\u7ebf\u7a0b\u91cc\u8fb9\u53bb&#xff0c;\u8981\u8fdb\u884c\u67d0\u4e9b\u64cd\u4f5c\u7684\u65f6\u5019\u4e5f\u662f\u628a\u4efb\u52a1\u538b\u5165\u5230\u6211\u4eec\u5bf9eventloop&#xff0c;\u5b83\u7684\u4efb\u52a1\u961f\u5217\u91cc\u8fb9\u3002<\/p>\n<p>\u3010\u83b7\u53d6evnetloop\u540c\u6b65\u95ee\u9898\u3011 \u8981\u907f\u514d\u5f53\u6211\u4eec\u7684\u7ebf\u7a0b\u521a\u521b\u5efa\u8d77\u6765\u4e4b\u540e&#xff0c;\u8fd8\u6ca1\u6765\u5f97\u53ca\u5b9e\u4f8b\u5316\u521b\u5efaeventloop\u8be5\u5bf9\u8c61\u7684\u65f6\u5019&#xff0c;\u8fd9\u65f6\u5019\u5916\u754c\u5982\u679c\u8981\u83b7\u53d6\u8be5\u7ebf\u7a0b\u7684eventloop&#xff0c;\u8c03\u7528Getloop\u64cd\u4f5c\u65f6&#xff0c;\u83b7\u53d6\u5230\u7684\u5c31\u4e3a\u7a7a\u3002\u6240\u4ee5\u8fd9\u91cc\u5b58\u5728\u4e00\u4e2a\u540c\u6b65\u95ee\u9898&#xff0c;\u4e5f\u5c31\u662f\u4ece\u5c5e\u7ebf\u7a0b\u8981\u5148\u5b9e\u4f8b\u5316eventloop\u5bf9\u8c61&#xff0c;\u4e3b\u7ebf\u7a0b\u624d\u80fd\u591f\u83b7\u53d6eventloop\u5bf9\u8c61\u3002 \u6240\u4ee5\u8fd9\u91cc\u9762\u9700\u8981\u4e24\u4e2a\u4e1c\u897f&#xff1a;\u9501\u4e0e\u6761\u4ef6\u53d8\u91cf\u3002<\/p>\n<p>\u8fd92\u4e2a\u4e1c\u897f&#xff0c;\u5b83\u7684\u4e00\u4e2a\u529f\u80fd\u5c31\u662f\u7528\u4e8e\u90a3\u4e48\u5b9e\u73b0\u6211\u4eec\u7684\u4e00\u4e2aloop\u64cd\u4f5c\u7684\u4e00\u4e2a\u540c\u6b65\u5173\u7cfb\u3002\u56e0\u4e3a\u5462&#xff1f;\u6211\u4eec\u8981\u907f\u514d\u90a3\u4e48\u7ebf\u7a0b\u521b\u5efa\u4e4b\u540e&#xff0c;\u4f46\u662f\u6211\u4eec\u7684eventloop&#xff0c;\u8fd8\u6ca1\u6709\u88ab\u5b9e\u4f8b\u5316\u4e4b\u524d\u5c31\u53bb\u83b7\u53d6loop\u7684\u64cd\u4f5c&#xff0c;\u8fd9\u6837\u7684\u83b7\u53d6\u662f\u4f1a\u51fa\u95ee\u9898&#xff0c;\u5c31\u662f\u4e00\u4e2a\u7a7a\u4e86\u5bf9\u4e0d\u5bf9\u6240\u4ee5\u8981\u7ed9\u5b83\u540c\u6b65\u7ba1\u7406\u8d77\u6765&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u4f60\u83b7\u53d6loop\u7684\u65f6\u5019&#xff0c;\u5fc5\u987b\u662f\u5b83loop\u5df2\u7ecf\u90a3\u4e48\u5b9e\u4f8b\u5316\u5b8c\u4e86\u624d\u53ef\u4ee5\u4e4b\u95f4\u7684&#xff0c;\u4f60\u5982\u679c\u6ca1\u6709\u5b9e\u4f8b\u5316\u5b8c\u90a3\u5c31\u4e0d\u8ba9\u4f60\u83b7\u53d6\u3002<\/p>\n<p>\u4e5f\u5c31\u662f\u5728\u83b7\u53d6eventloop\u5bf9\u8c61\u6307\u9488\u65f6&#xff0c;\u8bbe\u7f6e\u4e00\u4e2a\u6761\u4ef6&#xff1a;eventloop\u5bf9\u8c61\u6307\u9488\u4e0d\u4e3a\u7a7a\u3002 \u5982\u679c\u8fd9\u4e2a\u65f6\u5019\u4e0d\u6ee1\u8db3&#xff0c;\u5219\u4e3b\u7ebf\u7a0b\u5c31\u53bb\u6761\u4ef6\u53d8\u91cf\u4e0b\u963b\u585e\u7b49\u5f85&#xff0c;\u5982\u679c\u6ee1\u8db3\u6761\u4ef6\u5c31\u4f1a\u88ab\u5524\u9192&#xff0c;\u53bb\u83b7\u53d6eventloop\u5bf9\u8c61\u6307\u9488\u3002 \u800c\u5728\u7ebf\u7a0b\u7684\u5165\u53e3\u51fd\u6570\u91cc\u9762&#xff0c;\u5728\u521a\u521b\u5efa\u5b9e\u4f8b\u5316eventloop\u5bf9\u8c61\u4e4b\u540e&#xff0c;\u5c31\u7acb\u5373\u53d1\u9001\u901a\u77e5&#xff0c;\u5524\u9192\u4e3b\u7ebf\u7a0b\u3002<\/p>\n<h3>1.1\u6210\u5458\u53d8\u91cf<\/h3>\n<p><span class=\"token keyword\">private<\/span><span class=\"token operator\">:<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>thread _thread<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u7528\u6765\u521b\u5efa\u7ebf\u7a0b&#xff0c;eventloop\u7ed1\u5b9a\u7684\u7ebf\u7a0b<\/span><br \/>\n    EventLoop <span class=\"token operator\">*<\/span>_loop<span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ Eventloop\u7684\u6307\u9488\u53d8\u91cf&#xff0c;\u8fd9\u91cc\u4e0d\u80fd\u5b9e\u4f8b\u5316&#xff0c;\u5fc5\u987b\u5728\u521b\u5efa\u7ebf\u7a0b\u91cc\u9762\u5b9e\u4f8b\u5316eventloop<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u4e0b\u9762\u4e24\u4e2a\u7528\u6765\u4fdd\u8bc1loop\u7684\u540c\u6b65\u6027&#xff0c;\u5fc5\u987b\u5148\u5b9e\u4f8b\u5316\u5b8cloop&#xff0c;\u624d\u80fd\u83b7\u53d6loop<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>mutex _mutex<span class=\"token punctuation\">;<\/span>             <span class=\"token comment\">\/\/ \u9501&#xff0c;\u7528\u6765\u4fdd\u62a4loop\u8d44\u6e90<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>condition_variable _cond<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u6761\u4ef6\u53d8\u91cf<\/span><\/p>\n<h3>1.2\u6784\u9020\u51fd\u6570<\/h3>\n<p>\u5728\u6784\u9020\u4e2d&#xff0c;\u5c31\u4f7f\u7528C&#043;&#043;\u4e2d\u7684\u7ebf\u7a0b\u5e93&#xff0c;\u521b\u5efa\u7ebf\u7a0b\u3002 \u6240\u4ee5\u8be5\u6a21\u5757\u5bf9\u8c61\u4e00\u65e6\u521b\u5efa\u51fa\u6765&#xff0c;\u5c31\u4ee3\u8868\u521b\u5efa\u4e86\u4e00\u4e2a\u7ebf\u7a0b\u4ee5\u53ca\u5bf9\u5e94\u7684eventloop\u5bf9\u8c61\u3002<\/p>\n<p><span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token function\">LoopThread<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">:<\/span> <span class=\"token function\">_loop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">_thread<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>LoopThread<span class=\"token operator\">::<\/span>ThreadEntry<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<h3>13\u7ebf\u7a0b\u5165\u53e3\u51fd\u6570<\/h3>\n<p>\u8be5\u7ebf\u7a0b\u4e00\u65e6\u521b\u5efa\u51fa\u6765&#xff0c;\u5c31\u8981\u6267\u884c\u7684\u4efb\u52a1\u5c31\u662f&#xff1a; 1.\u521b\u5efaeventloop\u5bf9\u8c61 2.\u5524\u9192\u4e3b\u7ebf\u7a0b 3.\u542f\u52a8eventloop (eventloop\u4e00\u65e6\u542f\u52a8\u5b83\u5c31\u4f1a\u5faa\u73af\u76d1\u63a7\u5728\u5b83\u4e0a\u9762\u7684\u63cf\u8ff0\u7b26\u7684\u5404\u79cd\u4e8b\u4ef6\u662f\u5426\u5c31\u7eea&#xff0c;\u4e00\u65e6\u5c31\u7eea\u5c31\u4f1a\u83b7\u53d6\u5c31\u7eea\u7684\u4e8b\u4ef6\u4ee5\u53ca\u63cf\u8ff0\u7b26&#xff0c;\u6267\u884c\u5bf9\u5e94\u7684\u56de\u8c03\u51fd\u6570&#xff0c;\u5e76\u4e14\u6267\u884c\u4efb\u52a1\u961f\u5217\u4e2d\u7684\u4efb\u52a1)<\/p>\n<p><span class=\"token keyword\">private<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u7ebf\u7a0b\u7684\u5165\u53e3\u51fd\u6570<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">ThreadEntry<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u9996\u5148\u521b\u5efa\u5bf9\u5e94\u7684Eventloop\u5bf9\u8c61<\/span><br \/>\n        EventLoop loop<span class=\"token punctuation\">;<\/span><br \/>\n        _loop <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>loop<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u521b\u5efa\u5b8c\u5c31\u5524\u9192\u53ef\u80fd\u963b\u585e\u7684\u4e3b\u7ebf\u7a0b<\/span><br \/>\n        _cond<span class=\"token punctuation\">.<\/span><span class=\"token function\">notify_all<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u8be5\u7ebf\u7a0b\u5c31\u5f00\u59cb\u542f\u52a8\u5de5\u4f5c&#xff1a;<\/span><br \/>\n        _loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">Start<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ 1.\u8fdb\u884c\u4e8b\u4ef6\u76d1\u63a7,\u5e76\u83b7\u53d6\u5c31\u7eea\u7684\u4e8b\u4ef6\u548cfd 2.\u8fdb\u884c\u5c31\u7eea\u4e8b\u4ef6\u5904\u74063.\u6267\u884c\u4efb\u52a1\u961f\u5217\u91cc\u7684\u4efb\u52a1<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h3>1.4\u83b7\u53d6eventloop\u5bf9\u8c61GetLoop()<\/h3>\n<p> <span class=\"token comment\">\/\/ \u83b7\u53d6\u8be5\u7ebf\u7a0b\u5bf9\u5e94\u7684loop\u662f\u7531\u4e3b\u7ebf\u6267\u884c\u7684&#xff0c;\u6240\u4ee5\u5b58\u5728\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898&#xff0c;\u5e76\u4e14\u8fd8\u8981\u4fdd\u8bc1loop\u7684\u540c\u6b65\u95ee\u9898<\/span><br \/>\n    EventLoop <span class=\"token operator\">*<\/span><span class=\"token function\">GetLoop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        EventLoop <span class=\"token operator\">*<\/span>loop <span class=\"token operator\">&#061;<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u4e3a\u4e86\u4fdd\u8bc1\u4e34\u754c\u8d44\u6e90_loop\u7684\u5b89\u5168\u6027&#xff0c;\u5728\u8bbf\u95ee\u65f6\u6700\u540e\u5c06\u4e34\u754c\u8d44\u6e90\u62f7\u8d1d\u8fc7\u53bb&#xff0c;\u6700\u540e\u8fd4\u56de\u7684\u65f6\u5019\u5c31\u4e0d\u6d89\u53ca\u4e34\u754c\u8d44\u6e90\u7684\u8bbf\u95ee<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            std<span class=\"token operator\">::<\/span>unique_lock<span class=\"token operator\">&lt;<\/span>std<span class=\"token operator\">::<\/span>mutex<span class=\"token operator\">&gt;<\/span> <span class=\"token function\">_lock<\/span><span class=\"token punctuation\">(<\/span>_mutex<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u52a0\u9501<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u786e\u4fdd\u83b7\u53d6_loop\u4e4b\u524d\u5df2\u7ecf\u88ab\u5b9e\u4f8b\u5316<\/span><br \/>\n            _cond<span class=\"token punctuation\">.<\/span><span class=\"token function\">wait<\/span><span class=\"token punctuation\">(<\/span>_lock<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n                       <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">return<\/span> _loop <span class=\"token operator\">!&#061;<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5982\u679c\u8fd9\u65f6_loop\u4e3a\u7a7a&#xff0c;\u5219\u4e3b\u7ebf\u7a0b\u5c31\u4e00\u76f4\u963b\u585e\u5728\u6761\u4ef6\u53d8\u91cf\u7684\u961f\u5217\u4e2d<\/span><br \/>\n            loop <span class=\"token operator\">&#061;<\/span> _loop<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> loop<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5b9e\u73b0\u4e86\u6211\u4eec\u7684\u4e00\u4e2a\u4e3b\u4ecereact\u6a21\u578b&#xff0c;\u4e3b\u7ebf\u7a0b\u53ea\u8d1f\u8d23\u5bf9\u76d1\u542c\u5957\u4ef6\u5b57\u7684\u5904\u7406&#xff0c;\u83b7\u53d6\u65b0\u8fde\u63a5 \u4fdd\u8bc1\u6211\u4eec\u8fde\u63a5\u7684\u4e00\u4e2a\u83b7\u53d6\u6548\u7387\u4e0d\u4f1a\u56e0\u4e3a\u6211\u4eec\u7684\u4e00\u4e2a\u4e1a\u52a1\u7684\u5904\u7406\u800c\u5bfc\u81f4\u65e0\u6cd5\u53bb\u83b7\u53d6\u8fde\u63a5 \u800c\u6211\u4eec\u7684\u4ece\u5c5ereact\u5462&#xff1f;\u5f53\u5b83\u83b7\u53d6\u5230\u65b0\u8fde\u63a5\u4e4b\u540e&#xff0c;\u5c06\u6211\u4eec\u7684\u65b0\u8fde\u63a5\u5206\u914d\u7ed9\u6211\u4eec\u7684\u4ece\u5c5ereact\u7ebf\u7a0b\u4e2d&#xff0c;\u8ba9\u4ece\u5c5e\u7ebf\u7a0b\u5bf9\u5b83\u8fdb\u884c\u4e00\u4e2a\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u8fdb\u884c\u4e8b\u4ef6\u76d1\u63a7\u7136\u540e\u4e8b\u4ef6\u7684\u5904\u7406\u4ee5\u53ca\u4e1a\u52a1\u7684\u5904\u7406\u3002<\/p>\n<h2>2.LoopThreadPool\u6a21\u5757<\/h2>\n<p>LoopThreadPool\u7ebf\u7a0b\u6c60\u662f\u5bf9\u6240\u6709\u7684LoopThread\u7ebf\u7a0b\u8fdb\u884c\u7ba1\u7406\u53ca\u5206\u914d\u3002 \u4e3b\u8981\u63d0\u4f9b\u7684\u529f\u80fd\u662f&#xff1a; 1.\u80fd\u591f\u8ba9\u7528\u6237\u8bbe\u7f6e\u521b\u5efa\u51e0\u4e2a\u7ebf\u7a0b\u3002<\/p>\n<p>\u4e0d\u8fc7\u8981\u6ce8\u610f\u5f53\u7528\u6237\u8bbe\u7f6e\u7684\u4ece\u7ebf\u7a0b\u6570\u636e\u4e3a0\u65f6&#xff0c;\u8fd9\u65f6\u5019\u65b0\u8fde\u63a5\u7684\u4e8b\u4ef6\u76d1\u63a7\u5c31\u5fc5\u987b\u8981\u6709\u4e3b\u7ebf\u7a0b\u4e2d\u7684baseloop\u8fdb\u884c\u76d1\u63a7\u7ba1\u7406\u3002\u6240\u4ee5\u8be5\u7ebf\u7a0b\u6c60\u4e2d\u5fc5\u987b\u8981\u4f20\u5165\u4e3b\u7ebf\u7a0b\u7684baseloop\u5bf9\u8c61&#xff0c;\u4ee5\u9632\u6b62\u4ece\u5c5e\u7ebf\u7a0b\u7684\u6570\u91cf\u4e3a0\u3002<\/p>\n<p>\u5728\u4e3b\u4eceReactor\u6a21\u578b\u4e2d&#xff0c;\u4e3b\u7ebf\u7a0b\u53ea\u8d1f\u8d23\u83b7\u53d6\u65b0\u8fde\u63a5&#xff0c;\u800c\u4ece\u5c5e\u7ebf\u7a0b\u8d1f\u8d23\u5bf9\u8fde\u63a5\u8fdb\u884c\u76d1\u63a7\u548c\u5904\u7406&#xff0c;\u5f53\u7ebf\u7a0b\u6c60\u4e2d\u7ebf\u7a0b\u7684\u4e2a\u6570\u4e3a0\u65f6&#xff0c;\u5c31\u53d8\u6210\u4e86\u5355Reactor\u670d\u52a1\u5668&#xff0c;\u4e3b\u7ebf\u7a0b\u65e2\u8d1f\u8d23\u6216\u8005\u65b0\u8fde\u63a5&#xff0c;\u4e5f\u8d1f\u8d23\u65b0\u8fde\u63a5\u7684\u76d1\u63a7\u4e0e\u5904\u7406\u3002 2.\u80fd\u591f\u5c06\u7ebf\u7a0b\u6c60\u4e2d\u5bf9\u5e94\u7ebf\u7a0b\u7684eventloop\u5bf9\u8c61\u5206\u914d\u51fa\u53bb\u3002<\/p>\n<p>\u5982\u679c\u7ebf\u7a0b\u6c60\u4e2d\u7ebf\u7a0b\u7684\u4e2a\u6570\u4e3a0 &#xff0c;\u5219\u5c06\u4e3b\u7ebf\u7a0b\u7684Eventloop\u5206\u914d\u7ed9\u65b0\u8fde\u63a5&#xff0c;\u8fdb\u884c\u76d1\u63a7\u4e0e\u5904\u7406\u3002 \u5982\u679c\u7ebf\u7a0b\u6c60\u4e2d\u7ebf\u7a0b\u7684\u4e2a\u6570\u6709\u591a\u4e2a&#xff0c;\u5219\u91c7\u7528RR\u8f6e\u8f6c\u601d\u60f3&#xff0c;\u8fdb\u884c\u7ebf\u7a0b\u7684\u5206\u914d\u3002&#xff08;\u5c31\u662f\u5c06\u5bf9\u5e94\u7ebf\u7a0b\u7684Eventloop\u5bf9\u8c61\u83b7\u53d6\u5230\u7136\u540e\u5206\u914d\u7ed9Connection&#xff09; \u5c06\u6240\u6709\u7ebf\u7a0b\u7684Eventloop\u5bf9\u8c61\u90fd\u5b58\u50a8\u8d77\u6765&#xff0c;\u7136\u540e\u4f9d\u6b21\u5206\u914d\u51fa\u53bb\u5373\u53ef\u3002<\/p>\n<h3>2.1\u6210\u5458\u53d8\u91cf<\/h3>\n<p><span class=\"token keyword\">private<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> _thread_count<span class=\"token punctuation\">;<\/span>                  <span class=\"token comment\">\/\/ \u8981\u521b\u5efa\u7684\u7ebf\u7a0b\u7684\u6570\u91cf<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> _loop_idx<span class=\"token punctuation\">;<\/span>                      <span class=\"token comment\">\/\/ \u8981\u5206\u914d\u7684loop\u4e0b\u6807<\/span><br \/>\n    EventLoop <span class=\"token operator\">*<\/span>_baseloop<span class=\"token punctuation\">;<\/span>               <span class=\"token comment\">\/\/ \u4e3b\u7ebf\u7a0b\u7684loop&#xff0c;\u5916\u754c\u4f20\u5165\u8fdb\u6765&#xff0c;\u5982\u679c\u8981\u521b\u5efa\u7684\u4ece\u7ebf\u7a0b\u6570\u636e\u4e3a0&#xff0c;\u90a3\u4e48\u5c31\u5206\u914d\u51fa\u53bb\u7684\u5c31\u662f\u4e3b\u7ebf\u7a0b\u7684loop<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>vector<span class=\"token operator\">&lt;<\/span>LoopThread <span class=\"token operator\">*<\/span><span class=\"token operator\">&gt;<\/span> _threads<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u4fdd\u5b58\u6240\u6709\u7684LoopThread\u7ebf\u7a0b\u5bf9\u8c61<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>vector<span class=\"token operator\">&lt;<\/span>EventLoop <span class=\"token operator\">*<\/span><span class=\"token operator\">&gt;<\/span> _loops<span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ \u4fdd\u5b58\u6240\u6709\u7ebf\u7a0b\u5bf9\u5e94\u7684eventloop&#xff0c;\u7136\u540e\u4f9d\u6b21\u5206\u914d\u51fa\u53bb\u3002<\/span><\/p>\n<h3>2.2\u6784\u9020\u51fd\u6570<\/h3>\n<p>\u7ebf\u7a0b\u7684\u6570\u91cf\u5728\u521d\u59cb\u5316\u65f6\u4e0d\u8bbe\u7f6e&#xff0c;\u7531\u7528\u6237\u8c03\u7528\u63a5\u53e3\u8bbe\u7f6e\u3002 \u5916\u754c\u9700\u8981\u5c06\u4e3b\u7ebf\u7a0b\u7684baseloop\u5bf9\u8c61\u4f20\u5165\u8fdb\u6765&#xff0c;\u4ee5\u9632\u6b62\u7ebf\u7a0b\u6c60\u4e2d\u6ca1\u6709\u7ebf\u7a0b\u3002<\/p>\n<p><span class=\"token function\">LoopThreadPool<\/span><span class=\"token punctuation\">(<\/span>EventLoop <span class=\"token operator\">*<\/span>baseloop<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">:<\/span> <span class=\"token function\">_thread_count<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">_loop_idx<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">_baseloop<\/span><span class=\"token punctuation\">(<\/span>baseloop<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<h3>2.3\u914d\u7f6e\u7ebf\u7a0b\u6570\u91cf<\/h3>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">SetThreadCount<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> count<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        _thread_count <span class=\"token operator\">&#061;<\/span> count<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h3>2.4\u6309\u7167\u914d\u7f6e\u6570\u91cf\u521b\u5efa\u7ebf\u7a0b<\/h3>\n<p>\u521b\u5efa\u7ebf\u7a0b\u65f6&#xff0c;\u5c06\u6240\u6709\u7ebf\u7a0b\u4ee5\u53ca\u7ebf\u7a0b\u5bf9\u5e94\u7684eventloop\u5bf9\u8c61\u90fd\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002 \u7136\u540e\u6839\u636e\u4e0b\u6807\u5c31\u53ef\u4ee5\u4f9d\u6b21\u5206\u914d\u7ebf\u7a0b\u5bf9\u5e94\u7684eventloop\u5bf9\u8c61\u4e86\u3002<\/p>\n<p> <span class=\"token keyword\">void<\/span> <span class=\"token function\">CreateLoopThread<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_thread_count <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\">\/\/ \u5982\u679c\u5927\u4e8e0\u5c31\u5c06\u6240\u6709\u7684\u7ebf\u7a0b\u90fd\u521b\u5efa\u51fa\u6765&#xff0c;\u5982\u679c\u5c0f\u4e8e0&#xff0c;\u90a3\u4e48\u5c31\u5fc5\u987b\u8981\u7528\u4e3b\u7ebf\u7a0b\u7684baseloop\u3002<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            _threads<span class=\"token punctuation\">.<\/span><span class=\"token function\">resize<\/span><span class=\"token punctuation\">(<\/span>_thread_count<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            _loops<span class=\"token punctuation\">.<\/span><span class=\"token function\">resize<\/span><span class=\"token punctuation\">(<\/span>_thread_count<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> _thread_count<span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token comment\">\/\/ \u521b\u5efa\u7ebf\u7a0b,\u5e76\u5c06\u6240\u6709\u7684\u7ebf\u7a0b\u7ba1\u7406\u8d77\u6765<\/span><br \/>\n                _threads<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token function\">LoopThread<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n                <span class=\"token comment\">\/\/ \u5e76\u4fdd\u5b58\u7ba1\u7406\u6240\u6709\u7ebf\u7a0b\u5bf9\u5e94\u7684loop<\/span><br \/>\n                _loops<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> _threads<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">GetLoop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h3>2.5\u4f9d\u6b21\u5206\u914dEventloop\u5bf9\u8c61<\/h3>\n<p>\u5982\u679c\u7ebf\u7a0b\u6c60\u4e2d\u7ebf\u7a0b\u7684\u4e2a\u6570\u4e3a0&#xff0c;\u8fd9\u65f6\u5019\u5206\u914d\u51fa\u53bb\u7684eventloop\u5bf9\u8c61\u5c31\u662f\u4e3b\u7ebf\u7a0b\u7684baseloop\u5bf9\u8c61\u3002\u4e3b\u7ebf\u7a0beventloop\u65e2\u83b7\u53d6\u8fde\u63a5&#xff0c;\u4e5f\u8fdb\u884c\u8fde\u63a5\u76d1\u63a7\u4e0e\u5904\u7406\u3002 \u5426\u5219\u5c31\u6309\u7167\u8f6e\u8f6c\u5f62\u5f0f\u4f9d\u6b21\u5206\u914d\u51fa\u53bb\u3002<\/p>\n<p> EventLoop <span class=\"token operator\">*<\/span><span class=\"token function\">AssignLoop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5982\u679c\u4ece\u7ebf\u7a0b\u7684\u6570\u91cf\u4e3a0&#xff0c;\u90a3\u4e48\u5206\u914d\u51fa\u53bb\u7684loop\u5c31\u662f\u4e3b\u7ebf\u7a0b\u5bf9\u5e94\u7684loop<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_thread_count <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> _baseloop<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        _loop_idx <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span>_loop_idx <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">%<\/span> _thread_count<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> _loops<span class=\"token punctuation\">[<\/span>_loop_idx<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb991\u6b21\uff0c\u70b9\u8d5e23\u6b21\uff0c\u6536\u85cf17\u6b21\u3002\u6211\u4eec\u8981\u907f\u514d\u90a3\u4e48\u7ebf\u7a0b\u521b\u5efa\u4e4b\u540e\uff0c\u4f46\u662f\u6211\u4eec\u7684eventloop\uff0c\u8fd8\u6ca1\u6709\u88ab\u5b9e\u4f8b\u5316\u4e4b\u524d\u5c31\u53bb\u83b7\u53d6loop\u7684\u64cd\u4f5c\uff0c\u8fd9\u6837\u7684\u83b7\u53d6\u662f\u4f1a\u51fa\u95ee\u9898\uff0c\u5c31\u662f\u4e00\u4e2a\u7a7a\u4e86\u5bf9\u4e0d\u5bf9\u6240\u4ee5\u8981\u7ed9\u5b83\u540c\u6b65\u7ba1\u7406\u8d77\u6765\uff0c\u4e5f\u5c31\u662f\u8bf4\u4f60\u83b7\u53d6loop\u7684\u65f6\u5019\uff0c\u5fc5\u987b\u662f\u5b83loop\u5df2\u7ecf\u90a3\u4e48\u5b9e\u4f8b\u5316\u5b8c\u4e86\u624d\u53ef\u4ee5\u4e4b\u95f4\u7684\uff0c\u4f60\u5982\u679c\u6ca1\u6709\u5b9e\u4f8b\u5316\u5b8c\u90a3\u5c31\u4e0d\u8ba9\u4f60\u83b7\u53d6\u3002\u6bd4\u5982\u5728\u6267\u884c\u5404\u79cd\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u8fdb\u884c\u4e8b\u4ef6\u76d1\u63a7\u7684\u65f6\u5019\uff0c\u5b83\u5c31\u4f1a\u7ed1\u5b9a\u5230\u6211\u4eeceventloop\u5bf9\u5e94\u7684\u7ebf\u7a0b\u91cc\u8fb9\u53bb\uff0c\u8981\u8fdb\u884c\u67d0\u4e9b\u64cd\u4f5c\u7684\u65f6\u5019\u4e5f\u662f\u628a\u4efb\u52a1\u538b\u5165\u5230\u6211\u4eec\u5bf9eventloop\uff0c\u5b83\u7684\u4efb\u52a1\u961f\u5217\u91cc\u8fb9\u3002\u800c\u6211\u4eec\u7684\u4ece\u5c5ereact\u5462\uff1f<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,43,427,185],"topic":[],"class_list":["post-47025","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-43","tag-427","tag-185"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011LoopThreadPool\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/47025.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011LoopThreadPool\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb991\u6b21\uff0c\u70b9\u8d5e23\u6b21\uff0c\u6536\u85cf17\u6b21\u3002\u6211\u4eec\u8981\u907f\u514d\u90a3\u4e48\u7ebf\u7a0b\u521b\u5efa\u4e4b\u540e\uff0c\u4f46\u662f\u6211\u4eec\u7684eventloop\uff0c\u8fd8\u6ca1\u6709\u88ab\u5b9e\u4f8b\u5316\u4e4b\u524d\u5c31\u53bb\u83b7\u53d6loop\u7684\u64cd\u4f5c\uff0c\u8fd9\u6837\u7684\u83b7\u53d6\u662f\u4f1a\u51fa\u95ee\u9898\uff0c\u5c31\u662f\u4e00\u4e2a\u7a7a\u4e86\u5bf9\u4e0d\u5bf9\u6240\u4ee5\u8981\u7ed9\u5b83\u540c\u6b65\u7ba1\u7406\u8d77\u6765\uff0c\u4e5f\u5c31\u662f\u8bf4\u4f60\u83b7\u53d6loop\u7684\u65f6\u5019\uff0c\u5fc5\u987b\u662f\u5b83loop\u5df2\u7ecf\u90a3\u4e48\u5b9e\u4f8b\u5316\u5b8c\u4e86\u624d\u53ef\u4ee5\u4e4b\u95f4\u7684\uff0c\u4f60\u5982\u679c\u6ca1\u6709\u5b9e\u4f8b\u5316\u5b8c\u90a3\u5c31\u4e0d\u8ba9\u4f60\u83b7\u53d6\u3002\u6bd4\u5982\u5728\u6267\u884c\u5404\u79cd\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u8fdb\u884c\u4e8b\u4ef6\u76d1\u63a7\u7684\u65f6\u5019\uff0c\u5b83\u5c31\u4f1a\u7ed1\u5b9a\u5230\u6211\u4eeceventloop\u5bf9\u5e94\u7684\u7ebf\u7a0b\u91cc\u8fb9\u53bb\uff0c\u8981\u8fdb\u884c\u67d0\u4e9b\u64cd\u4f5c\u7684\u65f6\u5019\u4e5f\u662f\u628a\u4efb\u52a1\u538b\u5165\u5230\u6211\u4eec\u5bf9eventloop\uff0c\u5b83\u7684\u4efb\u52a1\u961f\u5217\u91cc\u8fb9\u3002\u800c\u6211\u4eec\u7684\u4ece\u5c5ereact\u5462\uff1f\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/47025.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T21:41:56+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/47025.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/47025.html\",\"name\":\"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011LoopThreadPool\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T21:41:56+00:00\",\"dateModified\":\"2025-07-29T21:41:56+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/47025.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/47025.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/47025.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011LoopThreadPool\u6a21\u5757\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011LoopThreadPool\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/47025.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011LoopThreadPool\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb991\u6b21\uff0c\u70b9\u8d5e23\u6b21\uff0c\u6536\u85cf17\u6b21\u3002\u6211\u4eec\u8981\u907f\u514d\u90a3\u4e48\u7ebf\u7a0b\u521b\u5efa\u4e4b\u540e\uff0c\u4f46\u662f\u6211\u4eec\u7684eventloop\uff0c\u8fd8\u6ca1\u6709\u88ab\u5b9e\u4f8b\u5316\u4e4b\u524d\u5c31\u53bb\u83b7\u53d6loop\u7684\u64cd\u4f5c\uff0c\u8fd9\u6837\u7684\u83b7\u53d6\u662f\u4f1a\u51fa\u95ee\u9898\uff0c\u5c31\u662f\u4e00\u4e2a\u7a7a\u4e86\u5bf9\u4e0d\u5bf9\u6240\u4ee5\u8981\u7ed9\u5b83\u540c\u6b65\u7ba1\u7406\u8d77\u6765\uff0c\u4e5f\u5c31\u662f\u8bf4\u4f60\u83b7\u53d6loop\u7684\u65f6\u5019\uff0c\u5fc5\u987b\u662f\u5b83loop\u5df2\u7ecf\u90a3\u4e48\u5b9e\u4f8b\u5316\u5b8c\u4e86\u624d\u53ef\u4ee5\u4e4b\u95f4\u7684\uff0c\u4f60\u5982\u679c\u6ca1\u6709\u5b9e\u4f8b\u5316\u5b8c\u90a3\u5c31\u4e0d\u8ba9\u4f60\u83b7\u53d6\u3002\u6bd4\u5982\u5728\u6267\u884c\u5404\u79cd\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u8fdb\u884c\u4e8b\u4ef6\u76d1\u63a7\u7684\u65f6\u5019\uff0c\u5b83\u5c31\u4f1a\u7ed1\u5b9a\u5230\u6211\u4eeceventloop\u5bf9\u5e94\u7684\u7ebf\u7a0b\u91cc\u8fb9\u53bb\uff0c\u8981\u8fdb\u884c\u67d0\u4e9b\u64cd\u4f5c\u7684\u65f6\u5019\u4e5f\u662f\u628a\u4efb\u52a1\u538b\u5165\u5230\u6211\u4eec\u5bf9eventloop\uff0c\u5b83\u7684\u4efb\u52a1\u961f\u5217\u91cc\u8fb9\u3002\u800c\u6211\u4eec\u7684\u4ece\u5c5ereact\u5462\uff1f","og_url":"https:\/\/www.wsisp.com\/helps\/47025.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T21:41:56+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/47025.html","url":"https:\/\/www.wsisp.com\/helps\/47025.html","name":"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011LoopThreadPool\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T21:41:56+00:00","dateModified":"2025-07-29T21:41:56+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/47025.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/47025.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/47025.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011LoopThreadPool\u6a21\u5757"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/47025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=47025"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/47025\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=47025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=47025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=47025"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=47025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}