{"id":42584,"date":"2024-12-01T11:36:16","date_gmt":"2024-12-01T03:36:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42584\/"},"modified":"2024-12-01T11:36:16","modified_gmt":"2024-12-01T03:36:16","slug":"%e7%90%86%e8%a7%a3go%e4%b8%ad%e7%9a%84synccond%ef%bc%9a%e7%94%9f%e4%ba%a7%e8%80%85-%e6%b6%88%e8%b4%b9%e8%80%85%e5%9c%ba%e6%99%af%e4%b8%ad%e7%9a%84goroutine%e5%90%8c%e6%ad%a5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42584\/","title":{"rendered":"\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65"},"content":{"rendered":"<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300a\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241129\/173286328067496530dd750.jpg\" class=\"aligncenter\" title=\"\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65\u63d2\u56fe\" alt=\"\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65\u63d2\u56fe\" \/>,\u5728\u5e76\u53d1\u7f16\u7a0b\u4e2d\uff0c\u540c\u6b65\u662f\u9632\u6b62\u6570\u636e\u7ade\u4e89\u5e76\u786e\u4fdd\u7ebf\u7a0b\u6216 goroutine \u4ee5\u534f\u8c03\u65b9\u5f0f\u8fd0\u884c\u7684\u5173\u952e\u3002<br \/>\n<strong>\u60f3\u8c61\u4e00\u4e0b\uff0c\u60a8\u5728\u534f\u8c03\u591a\u4e2a\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\uff08\u4f8b\u5982\u7f13\u51b2\u533a\u6216\u961f\u5217\uff09\u65f6\u9047\u5230\u95ee\u9898\u3002\u8fd9\u79cd\u7ecf\u5178\u7684\u5e76\u53d1\u6311\u6218\u88ab\u79f0\u4e3a<\/strong>\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u95ee\u9898<br \/>\n<strong>\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u540c\u6b65\u5bf9\u4e8e\u786e\u4fdd\u751f\u4ea7\u8005\u4e0d\u4f1a\u8986\u76d6\u6570\u636e\u4ee5\u53ca\u6d88\u8d39\u8005\u4e0d\u4f1a\u8bfb\u53d6\u65e0\u6548\u6216\u9648\u65e7\u7684\u6570\u636e\u81f3\u5173\u91cd\u8981\u3002\u540c\u6b65\u662f\u5fc5\u8981\u7684\uff0c\u56e0\u4e3a\u5982\u679c\u6ca1\u6709\u6b63\u786e\u7684\u540c\u6b65\uff0c\u540c\u65f6\u8bbf\u95ee\u5171\u4eab\u6570\u636e\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7ade\u4e89\u6761\u4ef6\u3001\u6570\u636e\u635f\u574f\u6216\u5d29\u6e83\u3002\u5982\u679c\u7f13\u51b2\u533a\u5df2\u6ee1\uff0c\u751f\u4ea7\u8005\u9700\u8981\u7b49\u5f85\uff0c\u5982\u679c\u7f13\u51b2\u533a\u4e3a\u7a7a\uff0c\u6d88\u8d39\u8005\u9700\u8981\u7b49\u5f85\u3002 <\/strong>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b<br \/>\n<strong>\u60a8\u6709\u4e00\u4e2a\u56fa\u5b9a\u5927\u5c0f\u7684\u6709\u754c\u7f13\u51b2\u533a\uff0c\u5e76\u4e14\u60a8\u9700\u8981\u7ba1\u7406\u591a\u4e2a\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u4e4b\u95f4\u5bf9\u5176\u7684\u8bbf\u95ee\u3002<\/strong>,\u7f13\u51b2\u533a<br \/>\n<strong>\uff08\u6216\u961f\u5217\uff09\uff0c\u5176\u5927\u5c0f\u56fa\u5b9a\u3002\u591a\u4e2a\u751f\u4ea7\u8005\u751f\u6210\u9879\u76ee\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u7f13\u51b2\u533a\uff0c\u800c\u591a\u4e2a\u6d88\u8d39\u8005\u5219\u4ece\u4e2d\u5220\u9664\u9879\u76ee\u3002\u6311\u6218\u662f\uff1a<\/strong>,<br \/>\n<br \/>,\u521d\u59cb\u5316<br \/>\n<strong>:<\/strong><br \/>\n<br \/>,\u751f\u4ea7\u8005\u65b9\u6cd5\uff08\u751f\u4ea7\uff09<br \/>\n<strong>:<\/strong><br \/>\n<br \/>,\u6d88\u8d39\u65b9\u6cd5\uff08\u6d88\u8d39\uff09<br \/>\n<strong>:<\/strong><br \/>\n<br \/>,\u60f3\u8c61\u4e00\u4e0b\u60a8\u7684\u4efb\u52a1<br \/>\n<strong>\u591a\u4e2a goroutine \u9700\u8981\u7b49\u5f85\u7279\u5b9a\u6761\u4ef6\u624d\u80fd\u7ee7\u7eed\uff0c\u4f8b\u5982\uff1a<\/strong>,\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301golang\u5b66\u4e60\u7f51\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\u3002,\u4fe1\u53f7\uff08\uff09\u548c\u5e7f\u64ad\uff08\uff09<br \/>\n<strong>\uff1a <\/strong> <\/p>\n<ul>\n<li>signal()<strong>&nbsp;\u5524\u9192<\/strong>\u4e00\u4e2a<strong>&nbsp;\u7b49\u5f85\u7684 goroutine\uff0c\u5141\u8bb8\u5176\u83b7\u53d6\u9501\u5e76\u7ee7\u7eed\u3002<\/strong> <\/li>\n<li>broadcast()<strong>&nbsp;\u5524\u9192<\/strong>\u6240\u6709<strong>&nbsp;\u7b49\u5f85\u7684 goroutine\u3002<\/strong> <\/li>\n<\/ul>\n<p>,wait()<br \/>\n<strong>\uff1a\u5f53 goroutine \u8c03\u7528 wait() \u65f6\uff0c\u5b83\uff1a <\/strong> <\/p>\n<ul>\n  \u91ca\u653e\u5173\u8054\u7684\u9501\uff0c\u5141\u8bb8\u5176\u4ed6 goroutine \u8bbf\u95ee\u8be5\u8d44\u6e90\u3002 <\/p>\n<li> <\/li>\n<p>\u7b49\u5f85\uff08\u963b\u585e\uff09\u76f4\u5230\u53e6\u4e00\u4e2a goroutine \u53d1\u51fa\u7ee7\u7eed\u7684\u4fe1\u53f7\u3002 <\/p>\n<li> <\/li>\n<\/ul>\n<p>,sync.cond\u521d\u59cb\u5316<br \/>\n<strong>\uff1a\u5b83\u9700\u8981\u4e00\u4e2alocker\uff0c\u901a\u5e38\u662fsync.mutex\u6216sync.rwmutex\u6765\u63a7\u5236\u8bbf\u95ee\u3002\u6b64\u50a8\u7269\u67dc\u6709\u52a9\u4e8e\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90\u3002<\/strong>,\u53d1\u4fe1\u53f7<br \/>\n<strong>\uff1a\u5f53\u6ee1\u8db3\u6761\u4ef6\u65f6\uff0c\u5176\u4ed6 goroutine \u53ef\u4ee5\u5411\u7b49\u5f85\u7684 goroutine \u53d1\u51fa\u4fe1\u53f7\u4ee5\u7ee7\u7eed\u6267\u884c\u3002<\/strong>,\u963b\u585e<br \/>\n<strong>\uff1agoroutines \u53ef\u4ee5\u7b49\u5f85\u4fe1\u53f7\uff0c\u6682\u505c\u6267\u884c\u76f4\u5230\u6536\u5230\u901a\u77e5\u3002<\/strong>,\u6548\u7387<br \/>\n<strong>\uff1a\u901a\u8fc7\u8ba9 goroutine \u4f11\u7720\u76f4\u5230\u6536\u5230\u4fe1\u53f7\u6765\u51cf\u5c11\u7e41\u5fd9\u7b49\u5f85\u3002<\/strong>,\u60f3\u8c61\u4e00\u4e0b\uff0c\u60a8\u5728\u534f\u8c03\u591a\u4e2a\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\uff08\u4f8b\u5982\u7f13\u51b2\u533a\u6216\u961f\u5217\uff09\u65f6\u9047\u5230\u95ee\u9898\u3002\u8fd9\u79cd\u7ecf\u5178\u7684\u5e76\u53d1\u6311\u6218\u88ab\u79f0\u4e3a,\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300a\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002,<br \/>\n<b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65<\/span><\/p>\n<h1>\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65<\/h1>\n<p><span>\u6765\u6e90\uff1adev.to<\/span><br \/>\n<span>2024-11-29 14:54:56<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300a\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241129\/173286328067496530dd750.jpg\" class=\"aligncenter\" title=\"\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65\u63d2\u56fe\" alt=\"\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65\u63d2\u56fe\" \/><\/p>\n<p>\u5728\u5e76\u53d1\u7f16\u7a0b\u4e2d\uff0c\u540c\u6b65\u662f\u9632\u6b62\u6570\u636e\u7ade\u4e89\u5e76\u786e\u4fdd\u7ebf\u7a0b\u6216 goroutine \u4ee5\u534f\u8c03\u65b9\u5f0f\u8fd0\u884c\u7684\u5173\u952e\u3002 <strong>\u60f3\u8c61\u4e00\u4e0b\uff0c\u60a8\u5728\u534f\u8c03\u591a\u4e2a\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\uff08\u4f8b\u5982\u7f13\u51b2\u533a\u6216\u961f\u5217\uff09\u65f6\u9047\u5230\u95ee\u9898\u3002\u8fd9\u79cd\u7ecf\u5178\u7684\u5e76\u53d1\u6311\u6218\u88ab\u79f0\u4e3a<\/strong>\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u95ee\u9898<strong>\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u540c\u6b65\u5bf9\u4e8e\u786e\u4fdd\u751f\u4ea7\u8005\u4e0d\u4f1a\u8986\u76d6\u6570\u636e\u4ee5\u53ca\u6d88\u8d39\u8005\u4e0d\u4f1a\u8bfb\u53d6\u65e0\u6548\u6216\u9648\u65e7\u7684\u6570\u636e\u81f3\u5173\u91cd\u8981\u3002\u540c\u6b65\u662f\u5fc5\u8981\u7684\uff0c\u56e0\u4e3a\u5982\u679c\u6ca1\u6709\u6b63\u786e\u7684\u540c\u6b65\uff0c\u540c\u65f6\u8bbf\u95ee\u5171\u4eab\u6570\u636e\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7ade\u4e89\u6761\u4ef6\u3001\u6570\u636e\u635f\u574f\u6216\u5d29\u6e83\u3002\u5982\u679c\u7f13\u51b2\u533a\u5df2\u6ee1\uff0c\u751f\u4ea7\u8005\u9700\u8981\u7b49\u5f85\uff0c\u5982\u679c\u7f13\u51b2\u533a\u4e3a\u7a7a\uff0c\u6d88\u8d39\u8005\u9700\u8981\u7b49\u5f85\u3002 <\/strong>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b<strong>\u60a8\u6709\u4e00\u4e2a\u56fa\u5b9a\u5927\u5c0f\u7684\u6709\u754c\u7f13\u51b2\u533a\uff0c\u5e76\u4e14\u60a8\u9700\u8981\u7ba1\u7406\u591a\u4e2a\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u4e4b\u95f4\u5bf9\u5176\u7684\u8bbf\u95ee\u3002<\/strong> <\/p>\n<p> \u4ec0\u4e48\u662fsync.cond\uff1f <\/p>\n<h3> <\/h3>\n<p>go \u4e2d\u7684sync.cond \u662f\u4e00\u79cd\u4fe1\u53f7\u673a\u5236\uff0c\u5141\u8bb8 goroutine \u7b49\u5f85\u76f4\u5230\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u3002\u5b83\u5bf9\u4e8e\u534f\u8c03\u590d\u6742\u7684\u5de5\u4f5c\u6d41\u7a0b\u7279\u522b\u6709\u7528\uff0c\u5728\u8fd9\u4e9b\u5de5\u4f5c\u6d41\u7a0b\u4e2d\uff0c\u67d0\u4e9b goroutine \u9700\u8981\u6682\u505c\u6267\u884c\u5e76\u7b49\u5f85\u5176\u4ed6 goroutine \u5b8c\u6210\u67d0\u4e9b\u64cd\u4f5c\u3002 sync.cond \u80cc\u540e\u7684\u60f3\u6cd5\u975e\u5e38\u7b80\u5355\u4e14\u6613\u4e8e\u7406\u89e3\uff1a <\/p>\n<ul>\n<li>\u963b\u585e<strong>\uff1agoroutines \u53ef\u4ee5\u7b49\u5f85\u4fe1\u53f7\uff0c\u6682\u505c\u6267\u884c\u76f4\u5230\u6536\u5230\u901a\u77e5\u3002<\/strong> <\/li>\n<li>\u53d1\u4fe1\u53f7<strong>\uff1a\u5f53\u6ee1\u8db3\u6761\u4ef6\u65f6\uff0c\u5176\u4ed6 goroutine \u53ef\u4ee5\u5411\u7b49\u5f85\u7684 goroutine \u53d1\u51fa\u4fe1\u53f7\u4ee5\u7ee7\u7eed\u6267\u884c\u3002<\/strong> <\/li>\n<li>\u6548\u7387<strong>\uff1a\u901a\u8fc7\u8ba9 goroutine \u4f11\u7720\u76f4\u5230\u6536\u5230\u4fe1\u53f7\u6765\u51cf\u5c11\u7e41\u5fd9\u7b49\u5f85\u3002<\/strong> <\/li>\n<\/ul>\n<p> sync.cond \u7684\u5de5\u4f5c\u539f\u7406 <\/p>\n<h3> <\/h3>\n<ul>\n<li>sync.cond\u521d\u59cb\u5316<strong>\uff1a\u5b83\u9700\u8981\u4e00\u4e2alocker\uff0c\u901a\u5e38\u662fsync.mutex\u6216sync.rwmutex\u6765\u63a7\u5236\u8bbf\u95ee\u3002\u6b64\u50a8\u7269\u67dc\u6709\u52a9\u4e8e\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90\u3002<\/strong> <\/li>\n<li>wait()<strong>\uff1a\u5f53 goroutine \u8c03\u7528 wait() \u65f6\uff0c\u5b83\uff1a <\/strong>\n<ul>\n    \u91ca\u653e\u5173\u8054\u7684\u9501\uff0c\u5141\u8bb8\u5176\u4ed6 goroutine \u8bbf\u95ee\u8be5\u8d44\u6e90\u3002 <\/p>\n<li> <\/li>\n<p>\u7b49\u5f85\uff08\u963b\u585e\uff09\u76f4\u5230\u53e6\u4e00\u4e2a goroutine \u53d1\u51fa\u7ee7\u7eed\u7684\u4fe1\u53f7\u3002 <\/p>\n<li> <\/li>\n<\/ul>\n<\/li>\n<li>\u4fe1\u53f7\uff08\uff09\u548c\u5e7f\u64ad\uff08\uff09<strong>\uff1a <\/strong>\n<ul>\n<li>signal()<strong>&nbsp;\u5524\u9192<\/strong>\u4e00\u4e2a<strong>&nbsp;\u7b49\u5f85\u7684 goroutine\uff0c\u5141\u8bb8\u5176\u83b7\u53d6\u9501\u5e76\u7ee7\u7eed\u3002<\/strong> <\/li>\n<li>broadcast()<strong>&nbsp;\u5524\u9192<\/strong>\u6240\u6709<strong>&nbsp;\u7b49\u5f85\u7684 goroutine\u3002<\/strong> <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p> \u95ee\u9898\uff1a\u5177\u6709\u4e92\u65a5\u9501\u548c\u6761\u4ef6\u53d8\u91cf\u7684\u751f\u4ea7\u8005-\u6d88\u8d39\u8005 <\/p>\n<h3> <\/h3>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a <\/p>\n<p>\u7f13\u51b2\u533a<strong>\uff08\u6216\u961f\u5217\uff09\uff0c\u5176\u5927\u5c0f\u56fa\u5b9a\u3002\u591a\u4e2a\u751f\u4ea7\u8005\u751f\u6210\u9879\u76ee\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u7f13\u51b2\u533a\uff0c\u800c\u591a\u4e2a\u6d88\u8d39\u8005\u5219\u4ece\u4e2d\u5220\u9664\u9879\u76ee\u3002\u6311\u6218\u662f\uff1a<\/strong> <\/p>\n<ol>\n  \u786e\u4fdd\u751f\u4ea7\u8005\u4ec5\u5728\u7f13\u51b2\u533a\u6709\u7a7a\u95f4\u65f6\u6dfb\u52a0\u9879\u76ee\u3002 <\/p>\n<li> <\/li>\n<p>\u786e\u4fdd\u6d88\u8d39\u8005\u4ec5\u5728\u7f13\u51b2\u533a\u4e0d\u4e3a\u7a7a\u65f6\u79fb\u9664\u9879\u76ee\u3002 <\/p>\n<li> <\/li>\n<p>\u5411\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u53d1\u51fa\u53ef\u4ee5\u6dfb\u52a0\u6216\u5220\u9664\u9879\u76ee\u7684\u4fe1\u53f7\u3002 <\/p>\n<li> <\/li>\n<\/ol>\n<p>\u8fd9\u662f\u521d\u59cb\u4ee3\u7801\u7ed3\u6784\uff1a <\/p>\n<p><\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n    \"sync\"\n    \"time\"\n)\n\nconst buffersize = 5\n\ntype buffer struct {\n    data []int\n    mu   sync.mutex\n    cond *sync.cond\n}\n\nfunc (b *buffer) produce(item int) {\n    \/\/ producer logic to add item to the buffer\n}\n\nfunc (b *buffer) consume() int {\n    \/\/ consumer logic to remove item from the buffer\n    return 0\n}\n\nfunc main() {\n    buffer := &amp;buffer{data: make([]int, 0, buffersize)}\n    buffer.cond = sync.newcond(&amp;buffer.mu)\n    var wg sync.waitgroup\n\n    \/\/ start producer goroutines\n    for i := 1; i &lt;= 3; i++ {\n        wg.add(1)\n        go func(id int) {\n            defer wg.done()\n            for j := 0; j &lt; 5; j++ { \/\/ each producer creates 5 items\n                buffer.produce(id*10 + j) \/\/ produce unique items based on id and j\n                time.sleep(100 * time.millisecond)\n            }\n        }(i)\n    }\n\n    \/\/ start consumer goroutines\n    for i := 1; i &lt;= 3; i++ {\n        wg.add(1)\n        go func(id int) {\n            defer wg.done()\n            for j := 0; j &lt; 5; j++ { \/\/ each consumer consumes 5 items\n                item := buffer.consume()\n                fmt.printf(\"consumer %d consumed item %d\\n\", id, item)\n                time.sleep(150 * time.millisecond)\n            }\n        }(i)\n    }\n\n    wg.wait()\n    fmt.println(\"all producers and consumers finished.\")\n}\n<\/pre>\n<p> \u4f5c\u4e3a\u5de5\u7a0b\u5e08\uff0c\u6211\u4eec\u7684\u4efb\u52a1\u662f\u5b9e\u73b0\u751f\u4ea7\u548c\u6d88\u8d39\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e9b\u8981\u6c42\u3002 produce \u65b9\u6cd5\u5c06\u9879\u76ee\u6dfb\u52a0\u5230\u7f13\u51b2\u533a\uff0c\u5e76\u5728\u6dfb\u52a0\u9879\u76ee\u65f6\u901a\u77e5\u6d88\u8d39\u8005\u3002 consumer \u65b9\u6cd5\u4ece\u7f13\u51b2\u533a\u4e2d\u5220\u9664\u9879\u76ee\uff0c\u5e76\u5728\u9879\u76ee\u88ab\u5220\u9664\u65f6\u901a\u77e5\u751f\u4ea7\u8005\u3002\u8fd9\u4e2a\u95ee\u9898\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528sync.cond\u6765\u7b49\u5f85\u5e76\u5728\u7f13\u51b2\u533a\u5df2\u6ee1\u6216\u7a7a\u65f6\u53d1\u51fa\u4fe1\u53f7\u6765\u65e0\u7f1d\u89e3\u51b3\u3002 <\/p>\n<p> \u5728\u793a\u4f8b\u4e2d\u4f7f\u7528sync.cond <\/p>\n<h3> <\/h3>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u5728\u751f\u4ea7\u548c\u6d88\u8d39\u65b9\u6cd5\u4e2d\u4f7f\u7528sync.cond\u7684\u8be6\u7ec6\u4fe1\u606f\uff1a <\/p>\n<p>\u521d\u59cb\u5316<strong>:<\/strong> <\/p>\n<pre>buffer.cond = sync.newcond(&amp;buffer.mu)\n<\/pre>\n<ul>\n  \u8fd9\u91cc\uff0csync.newcond(&amp;buffer.mu) \u521b\u5efa\u4e00\u4e2a\u4e0e mu \u4e92\u65a5\u4f53\u5173\u8054\u7684\u65b0\u6761\u4ef6\u53d8\u91cf\u3002\u6761\u4ef6\u53d8\u91cf\u53ef\u4ee5\u7b49\u5f85\u7f13\u51b2\u533a\u7684\u66f4\u6539\u5e76\u53d1\u51fa\u4fe1\u53f7\uff08\u4f8b\u5982\u6dfb\u52a0\u6216\u5220\u9664\u9879\u76ee\uff09\u3002 <\/p>\n<li> <\/li>\n<\/ul>\n<p>\u751f\u4ea7\u8005\u65b9\u6cd5\uff08\u751f\u4ea7\uff09<strong>:<\/strong> <\/p>\n<pre>func (b *buffer) produce(item int) {\n    b.mu.lock()\n    defer b.mu.unlock()\n\n    \/\/ wait if the buffer is full\n    for len(b.data) == buffersize {\n        b.cond.wait() \/\/ release lock and wait until signaled\n    }\n\n    \/\/ add item to the buffer\n    b.data = append(b.data, item)\n    fmt.printf(\"produced item %d\\n\", item)\n\n    \/\/ signal a consumer that an item is available\n    b.cond.signal()\n}\n<\/pre>\n<ul>\n<li>\u9501\u5b9a<strong>\uff1a\u751f\u4ea7\u8005\u9501\u5b9a mu\uff0c\u4ee5\u786e\u4fdd\u5176\u5bf9 b.data \u5177\u6709\u72ec\u5360\u8bbf\u95ee\u6743\u9650\u3002<\/strong> <\/li>\n<li>wait if full<strong>\uff1a\u5982\u679c\u7f13\u51b2\u533a\u5df2\u6ee1\uff0c\u751f\u4ea7\u8005\u8c03\u7528 b.cond.wait()\uff1a <\/strong>\n<ul>\n    \u8fd9\u4f1a\u91ca\u653e b.mu \u4e0a\u7684\u9501\u5b9a\uff0c\u5141\u8bb8\u6d88\u8d39\u8005\u4f7f\u7528\u7f13\u51b2\u533a\u4e2d\u7684\u9879\u76ee\u3002 <\/p>\n<li> <\/li>\n<p>\u5b83\u4f1a\u7b49\u5f85\uff08\u963b\u585e\uff09\uff0c\u76f4\u5230\u6d88\u8d39\u8005\u53d1\u51fa\u4fe1\u53f7\u8868\u660e\u7f13\u51b2\u533a\u4e2d\u73b0\u5728\u6709\u7a7a\u95f4\u3002 <\/p>\n<li> <\/li>\n<\/ul>\n<\/li>\n<li>\u6dfb\u52a0\u9879\u76ee\u548c\u4fe1\u53f7<strong>\uff1a\u4e00\u65e6\u7f13\u51b2\u533a\u4e2d\u6709\u7a7a\u95f4\uff0c\u751f\u4ea7\u8005\uff1a <\/strong>\n<ul>\n    \u5c06\u9879\u76ee\u6dfb\u52a0\u5230\u7f13\u51b2\u533a\u3002 <\/p>\n<li> <\/li>\n<p>\u8c03\u7528 b.cond.signal() \u901a\u77e5\u4e00\u4e2a\u7b49\u5f85\u7684\u6d88\u8d39\u8005\uff08\u5982\u679c\u6709\uff09\u73b0\u5728\u6709\u4e00\u4e2a\u9879\u76ee\u53ef\u4ee5\u6d88\u8d39\u3002 <\/p>\n<li> <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u6d88\u8d39\u65b9\u6cd5\uff08\u6d88\u8d39\uff09<strong>:<\/strong> <\/p>\n<pre>func (b *Buffer) consume() int {\n    b.mu.Lock()\n    defer b.mu.Unlock()\n\n    \/\/ Wait if the buffer is empty\n    for len(b.data) == 0 {\n        b.cond.Wait() \/\/ Release lock and wait until signaled\n    }\n\n    \/\/ Remove item from the buffer\n    item := b.data[0]\n    b.data = b.data[1:]\n    fmt.Printf(\"Consumed item %d\\n\", item)\n\n    \/\/ Signal a producer that space is available\n    b.cond.Signal()\n\n    return item\n}\n<\/pre>\n<ul>\n<li>\u9501\u5b9a<strong>\uff1a\u6d88\u8d39\u8005\u9501\u5b9a mu \u4ee5\u786e\u4fdd\u5bf9 b.data \u7684\u72ec\u5360\u8bbf\u95ee\u3002<\/strong> <\/li>\n<li>wait if empty<strong>\uff1a\u5982\u679c\u7f13\u51b2\u533a\u4e3a\u7a7a\uff0c\u6d88\u8d39\u8005\u8c03\u7528 b.cond.wait()\uff1a <\/strong>\n<ul>\n    \u8fd9\u4f1a\u91ca\u653e b.mu \u4e0a\u7684\u9501\u5b9a\uff0c\u5141\u8bb8\u751f\u4ea7\u8005\u751f\u4ea7\u7269\u54c1\u5e76\u5728\u51c6\u5907\u5c31\u7eea\u65f6\u53d1\u51fa\u4fe1\u53f7\u3002 <\/p>\n<li> <\/li>\n<p>\u6d88\u8d39\u8005\u7b49\u5f85\u76f4\u5230\u6709\u5546\u54c1\u53ef\u4f9b\u6d88\u8d39\u3002 <\/p>\n<li> <\/li>\n<\/ul>\n<\/li>\n<li>\u6d88\u8d39\u9879\u76ee\u548c\u4fe1\u53f7<strong>\uff1a\u4e00\u65e6\u7f13\u51b2\u533a\u4e2d\u6709\u4e00\u4e2a\u9879\u76ee\uff0c\u6d88\u8d39\u8005\uff1a <\/strong>\n<ul>\n    \u5220\u9664\u5b83\u3002 <\/p>\n<li> <\/li>\n<p>\u8c03\u7528 b.cond.signal() \u901a\u77e5\u7b49\u5f85\u7684\u751f\u4ea7\u8005\u7f13\u51b2\u533a\u4e2d\u73b0\u5728\u6709\u7a7a\u95f4\u3002 <\/p>\n<li> <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p> \u4e3a\u4ec0\u4e48sync.cond\u5728\u8fd9\u91cc\u6709\u6548 <\/p>\n<h3> <\/h3>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff1a <\/p>\n<ul>\n<li>\u6761\u4ef6\u53d8\u91cf<strong>\uff1async.cond \u63d0\u4f9b\u4e86\u4e00\u79cd\u6709\u6548\u7684\u65b9\u6cd5\u6765\u5904\u7406\u7f13\u51b2\u533a\u5df2\u6ee1\u6216\u7a7a\u7684\u60c5\u51b5\uff0c\u800c\u65e0\u9700\u8fdb\u884c\u4e0d\u5fc5\u8981\u7684\u5faa\u73af\u3002<\/strong> <\/li>\n<li>\u7b49\u5f85\u548c\u4fe1\u53f7\u673a\u5236<strong>\uff1await() \u81ea\u52a8\u91ca\u653e\u9501\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5141\u8bb8\u5176\u4ed6 goroutine \u5728\u9002\u5f53\u7684\u65f6\u5019\u7ee7\u7eed\u6267\u884c\u6765\u9632\u6b62\u6b7b\u9501\u3002<\/strong> <\/li>\n<li>\u534f\u8c03<strong>\uff1a\u901a\u8fc7\u4f7f\u7528 signal()\uff0c\u6211\u4eec\u534f\u8c03\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u7684\u64cd\u4f5c\uff0c\u786e\u4fdd\u6bcf\u4e2a\u4eba\u4ec5\u5728\u5fc5\u8981\u65f6\u7b49\u5f85\uff0c\u9632\u6b62\u5b83\u4eec\u5728\u7a7a\u6216\u6ee1\u7684\u7f13\u51b2\u533a\u4e0a\u8fdb\u884c\u64cd\u4f5c\u3002<\/strong> <\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u534f\u8c03\u5141\u8bb8\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u5728\u6ca1\u6709\u5e72\u6270\u6216\u6b7b\u9501\u7684\u60c5\u51b5\u4e0b\u5171\u4eab\u7f13\u51b2\u533a\uff0c\u4ece\u800c\u6839\u636e\u7f13\u51b2\u533a\u7684\u72b6\u6001\u6709\u6548\u5730\u7ba1\u7406\u8bbf\u95ee\u3002 <\/p>\n<ul>\n  \u751f\u4ea7\u8005 <\/p>\n<li>\u7b49\u5f85<strong>\u5982\u679c\u7f13\u51b2\u533a\u5df2\u6ee1\uff0c\u5e76<\/strong>\u5728\u751f\u4ea7\u5b8c\u4ea7\u54c1\u540e\u5411\u6d88\u8d39\u8005\u53d1\u51fa\u4fe1\u53f7<strong>\u3002<\/strong> <\/li>\n<p>\u6d88\u8d39\u8005 <\/p>\n<li>\u7b49\u5f85<strong>\u5982\u679c\u7f13\u51b2\u533a\u4e3a\u7a7a\uff0c\u5e76\u4e14<\/strong>\u5728\u6d88\u8d39\u5b8c\u7269\u54c1\u540e\u5411<strong>\u751f\u4ea7\u8005\u53d1\u51fa\u4fe1\u53f7\u3002<\/strong> <\/li>\n<\/ul>\n<p> sync.cond \u7684\u5176\u4ed6\u573a\u666f <\/p>\n<h3> <\/h3>\n<p>\u60f3\u8c61\u4e00\u4e0b\u60a8\u7684\u4efb\u52a1<strong>\u591a\u4e2a goroutine \u9700\u8981\u7b49\u5f85\u7279\u5b9a\u6761\u4ef6\u624d\u80fd\u7ee7\u7eed\uff0c\u4f8b\u5982\uff1a<\/strong> <\/p>\n<ul>\n<li>\u6279\u5904\u7406<strong>\uff1a\u7b49\u5f85\u4efb\u52a1\u79ef\u7d2f\u5230\u4e00\u5b9a\u6570\u91cf\u624d\u4e00\u8d77\u5904\u7406\u3002<\/strong> <\/li>\n<li>\u4e8b\u4ef6\u534f\u8c03<strong>\uff1a\u7b49\u5f85\u4e8b\u4ef6\u53d1\u751f\uff08\u4f8b\u5982\uff0c\u8981\u52a0\u8f7d\u7684\u6570\u636e\u3001\u53ef\u7528\u7684\u8d44\u6e90\uff09\u3002<\/strong> <\/li>\n<li>rate limiting<strong>\uff1a\u63a7\u5236\u5e76\u53d1\u64cd\u4f5c\u6570\u91cf\uff0c\u9632\u6b62\u8d44\u6e90\u8017\u5c3d\u3002 \u5728\u8fd9\u4e9b\u573a\u666f\u4e2d\uff0csync.cond \u63d0\u4f9b\u4e86\u4e00\u79cd\u6839\u636e\u6761\u4ef6\u7ba1\u7406 goroutine \u540c\u6b65\u7684\u6709\u6548\u65b9\u6cd5\uff0c\u975e\u5e38\u9002\u5408\u9700\u8981\u5728\u5e76\u53d1\u4efb\u52a1\u4e4b\u95f4\u8fdb\u884c\u534f\u8c03\u7684\u95ee\u9898\u3002<\/strong> <\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301golang\u5b66\u4e60\u7f51\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\u3002<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664  <\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   Vue3 \u4e2d\u5982\u4f55\u5c06\u9875\u9762\u4e0a\u7684 PX \u5355\u4f4d\u8f6c\u6362\u4e3a REM\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u5982\u4f55\u5b9e\u73b0\u4e0e\u8bbe\u8ba1\u7a3f\u4e00\u81f4\u7684\u524d\u7aef\u8fdb\u5ea6\u6761\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300a\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002, ,\u5728\u5e76\u53d1\u7f16\u7a0b\u4e2d\uff0c\u540c\u6b65\u662f\u9632\u6b62\u6570\u636e\u7ade\u4e89\u5e76\u786e\u4fdd\u7ebf\u7a0b\u6216 goroutine \u4ee5\u534f\u8c03\u65b9\u5f0f\u8fd0\u884c\u7684\u5173\u952e\u3002 \u60f3\u8c61\u4e00\u4e0b\uff0c\u60a8\u5728\u534f\u8c03\u591a\u4e2a\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\uff08\u4f8b\u5982\u7f13\u51b2\u533a\u6216\u961f\u5217\uff09\u65f6\u9047\u5230\u95ee\u9898\u3002\u8fd9\u79cd\u7ecf\u5178\u7684\u5e76\u53d1\u6311\u6218\u88ab\u79f0\u4e3a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u95ee\u9898 \u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u540c\u6b65\u5bf9\u4e8e\u786e\u4fdd\u751f\u4ea7\u8005\u4e0d\u4f1a\u8986\u76d6\u6570\u636e\u4ee5\u53ca\u6d88\u8d39\u8005\u4e0d\u4f1a\u8bfb\u53d6\u65e0\u6548\u6216\u9648\u65e7\u7684\u6570\u636e\u81f3\u5173\u91cd\u8981\u3002\u540c\u6b65\u662f\u5fc5\u8981\u7684\uff0c\u56e0\u4e3a\u5982\u679c\u6ca1\u6709\u6b63\u786e\u7684\u540c\u6b65\uff0c\u540c\u65f6\u8bbf\u95ee\u5171\u4eab\u6570\u636e\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7ade\u4e89\u6761\u4ef6\u3001\u6570\u636e\u635f\u574f\u6216\u5d29\u6e83\u3002\u5982\u679c\u7f13\u51b2\u533a\u5df2\u6ee1\uff0c\u751f\u4ea7\u8005\u9700\u8981\u7b49\u5f85\uff0c\u5982\u679c\u7f13\u51b2\u533a\u4e3a\u7a7a\uff0c\u6d88\u8d39\u8005\u9700\u8981\u7b49\u5f85\u3002 \u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b \u60a8\u6709\u4e00\u4e2a\u56fa\u5b9a\u5927\u5c0f\u7684\u6709\u754c\u7f13\u51b2\u533a\uff0c\u5e76\u4e14\u60a8\u9700\u8981\u7ba1\u7406\u591a\u4e2a\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u4e4b\u95f4\u5bf9\u5176\u7684\u8bbf\u95ee\u3002,\u7f13\u51b2\u533a \uff08\u6216\u961f\u5217\uff09\uff0c\u5176\u5927\u5c0f\u56fa\u5b9a\u3002\u591a\u4e2a\u751f\u4ea7\u8005\u751f\u6210\u9879\u76ee\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u7f13\u51b2\u533a\uff0c\u800c\u591a\u4e2a\u6d88\u8d39\u8005\u5219\u4ece\u4e2d\u5220\u9664\u9879\u76ee\u3002\u6311\u6218\u662f\uff1a, ,\u521d\u59cb\u5316 : ,\u751f\u4ea7\u8005\u65b9\u6cd5\uff08\u751f\u4ea7\uff09 : ,\u6d88\u8d39\u65b9\u6cd5\uff08\u6d88\u8d39\uff09 : ,\u60f3\u8c61\u4e00\u4e0b\u60a8\u7684\u4efb\u52a1 \u591a\u4e2a goroutine \u9700\u8981\u7b49\u5f85\u7279\u5b9a\u6761\u4ef6\u624d\u80fd\u7ee7\u7eed\uff0c\u4f8b\u5982\uff1a,\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301golang\u5b66\u4e60\u7f51\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\u3002,\u4fe1\u53f7\uff08\uff09\u548c\u5e7f\u64ad\uff08\uff09 \uff1a signal()&nbsp;\u5524\u9192\u4e00\u4e2a&nbsp;\u7b49\u5f85\u7684 goroutine\uff0c\u5141\u8bb8\u5176\u83b7\u53d6\u9501\u5e76\u7ee7\u7eed\u3002 broadcast()&nbsp;\u5524\u9192\u6240\u6709&nbsp;\u7b49\u5f85\u7684 goroutine\u3002 ,wait() \uff1a\u5f53 goroutine \u8c03\u7528 wait() \u65f6\uff0c\u5b83\uff1a \u91ca\u653e\u5173\u8054\u7684\u9501\uff0c\u5141\u8bb8\u5176\u4ed6 goroutine \u8bbf\u95ee\u8be5\u8d44\u6e90\u3002 \u7b49\u5f85\uff08\u963b\u585e\uff09\u76f4\u5230\u53e6\u4e00\u4e2a goroutine \u53d1\u51fa\u7ee7\u7eed\u7684\u4fe1\u53f7\u3002 ,sync.cond\u521d\u59cb\u5316 \uff1a\u5b83\u9700\u8981\u4e00\u4e2alocker\uff0c\u901a\u5e38\u662fsync.mutex\u6216sync.rwmutex\u6765\u63a7\u5236\u8bbf\u95ee\u3002\u6b64\u50a8\u7269\u67dc\u6709\u52a9\u4e8e\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90\u3002,\u53d1\u4fe1\u53f7 \uff1a\u5f53\u6ee1\u8db3\u6761\u4ef6\u65f6\uff0c\u5176\u4ed6 goroutine \u53ef\u4ee5\u5411\u7b49\u5f85\u7684 goroutine \u53d1\u51fa\u4fe1\u53f7\u4ee5\u7ee7\u7eed\u6267\u884c\u3002,\u963b\u585e \uff1agoroutines \u53ef\u4ee5\u7b49\u5f85\u4fe1\u53f7\uff0c\u6682\u505c\u6267\u884c\u76f4\u5230\u6536\u5230\u901a\u77e5\u3002,\u6548\u7387 \uff1a\u901a\u8fc7\u8ba9 goroutine \u4f11\u7720\u76f4\u5230\u6536\u5230\u4fe1\u53f7\u6765\u51cf\u5c11\u7e41\u5fd9\u7b49\u5f85\u3002,\u60f3\u8c61\u4e00\u4e0b\uff0c\u60a8\u5728\u534f\u8c03\u591a\u4e2a\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\uff08\u4f8b\u5982\u7f13\u51b2\u533a\u6216\u961f\u5217\uff09\u65f6\u9047\u5230\u95ee\u9898\u3002\u8fd9\u79cd\u7ecf\u5178\u7684\u5e76\u53d1\u6311\u6218\u88ab\u79f0\u4e3a,\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300a\u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002, \u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65 \u7406\u89e3Go\u4e2d\u7684syncCond\uff1a\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u573a\u666f\u4e2d\u7684Goroutine\u540c\u6b65 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-42584","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=42584"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42584\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}