{"id":79726,"date":"2026-03-02T22:42:15","date_gmt":"2026-03-02T14:42:15","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/79726.html"},"modified":"2026-03-02T22:42:15","modified_gmt":"2026-03-02T14:42:15","slug":"%e3%80%90linux%e7%b3%bb%e7%bb%9f%e7%bc%96%e7%a8%8b%e3%80%91%ef%bc%88%e5%9b%9b%e5%8d%81%e4%b8%89%ef%bc%89%e7%ba%bf%e7%a8%8b%e5%90%8c%e6%ad%a5%e4%b8%8a%e7%af%87%ef%bc%9a%e4%bb%8e%e6%9d%a1%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/79726.html","title":{"rendered":"\u3010Linux\u7cfb\u7edf\u7f16\u7a0b\u3011\uff08\u56db\u5341\u4e09\uff09\u7ebf\u7a0b\u540c\u6b65\u4e0a\u7bc7\uff1a\u4ece\u6761\u4ef6\u53d8\u91cf\u5230\u751f\u4ea7\u6d88\u8d39\u6a21\u578b\uff0c\u5403\u900f\u591a\u7ebf\u7a0b\u534f\u4f5c\u7cbe\u9ad3"},"content":{"rendered":"<h2 id=\"%E2%80%8B%E7%BC%96%E8%BE%91\" style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260302144213-69a5a1c5f23b3.gif\" \/><\/h2>\n<hr \/>\n<h2 id=\"%E5%89%8D%E8%A8%80\">\u524d\u8a00<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u4e16\u754c\u91cc&#xff0c;\u7ebf\u7a0b\u4e92\u65a5\u89e3\u51b3\u4e86 \u201c\u591a\u4e2a\u7ebf\u7a0b\u62a2\u8d44\u6e90\u201d \u7684\u95ee\u9898&#xff0c;\u4fdd\u8bc1\u4e86\u4e34\u754c\u8d44\u6e90\u7684\u72ec\u5360\u8bbf\u95ee&#xff1b;\u4f46\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u6211\u4eec\u8fd8\u9700\u8981\u89e3\u51b3 \u201c\u7ebf\u7a0b\u95f4\u6709\u5e8f\u534f\u4f5c\u201d \u7684\u95ee\u9898 \u2014\u2014 \u6bd4\u5982\u751f\u4ea7\u8005\u5fc5\u987b\u5148\u751f\u4ea7&#xff0c;\u6d88\u8d39\u8005\u624d\u80fd\u6d88\u8d39&#xff1b;\u961f\u5217\u4e3a\u7a7a\u65f6\u6d88\u8d39\u8005\u4e0d\u80fd\u778e\u5fd9\u6d3b&#xff0c;\u961f\u5217\u4e3a\u6ee1\u65f6\u751f\u4ea7\u8005\u4e0d\u80fd\u786c\u585e\u6570\u636e\u3002\u8fd9\u79cd \u201c\u5728\u4fdd\u8bc1\u6570\u636e\u5b89\u5168\u7684\u524d\u63d0\u4e0b&#xff0c;\u8ba9\u7ebf\u7a0b\u6309\u9884\u5b9a\u987a\u5e8f\u6267\u884c\u201d \u7684\u673a\u5236&#xff0c;\u5c31\u662f\u7ebf\u7a0b\u540c\u6b65\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\u679c\u8bf4\u7ebf\u7a0b\u4e92\u65a5\u662f\u7ed9\u4e34\u754c\u8d44\u6e90\u88c5\u4e86 \u201c\u9632\u76d7\u95e8\u201d&#xff0c;\u90a3\u7ebf\u7a0b\u540c\u6b65\u5c31\u662f\u7ed9\u7ebf\u7a0b\u534f\u4f5c\u88c5\u4e86 \u201c\u4ea4\u901a\u4fe1\u53f7\u706f\u201d&#xff0c;\u8ba9\u7ebf\u7a0b\u5404\u53f8\u5176\u804c\u3001\u4e92\u4e0d\u803d\u8bef\u3002\u672c\u6587\u4f5c\u4e3a\u7ebf\u7a0b\u540c\u6b65\u7684\u4e0a\u7bc7&#xff0c;\u5c06\u4ece\u6838\u5fc3\u6982\u5ff5\u5165\u624b&#xff0c;\u6df1\u5165\u62c6\u89e3\u6761\u4ef6\u53d8\u91cf\u7684\u539f\u7406\u4e0e\u7528\u6cd5&#xff0c;\u518d\u901a\u8fc7\u7ecf\u5178\u7684\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u5b8c\u6210\u5b9e\u6218\u843d\u5730\u3002\u4e0b\u9762\u5c31\u8ba9\u6211\u4eec\u6b63\u5f0f\u5f00\u59cb\u5427&#xff01;\u00a0 \u00a0 \u00a0 \u00a0<\/p>\n<hr \/>\n<h2 id=\"main-toc\">\u76ee\u5f55<\/h2>\n<p id=\"%E5%89%8D%E8%A8%80-toc\" style=\"margin-left:0px\">\u524d\u8a00<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%E6%A0%B8%E5%BF%83%E6%A6%82%E5%BF%B5%EF%BC%9A%E6%90%9E%E6%87%82%20%E2%80%9C%E5%8D%8F%E4%BD%9C%E2%80%9D%20%E7%9A%84%E6%9C%AC%E8%B4%A8-toc\" style=\"margin-left:0px\">\u4e00\u3001\u7ebf\u7a0b\u540c\u6b65\u6838\u5fc3\u6982\u5ff5&#xff1a;\u641e\u61c2 \u201c\u534f\u4f5c\u201d \u7684\u672c\u8d28<\/p>\n<p id=\"1.1%20%E4%BB%80%E4%B9%88%E6%98%AF%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%EF%BC%9F-toc\" style=\"margin-left:40px\">1.1 \u4ec0\u4e48\u662f\u7ebf\u7a0b\u540c\u6b65&#xff1f;<\/p>\n<p id=\"1.2%20%E7%AB%9E%E6%80%81%E6%9D%A1%E4%BB%B6%EF%BC%9A%E5%90%8C%E6%AD%A5%E8%A6%81%E8%A7%A3%E5%86%B3%E7%9A%84%E6%A0%B8%E5%BF%83%E9%97%AE%E9%A2%98-toc\" style=\"margin-left:40px\">1.2 \u7ade\u6001\u6761\u4ef6&#xff1a;\u540c\u6b65\u8981\u89e3\u51b3\u7684\u6838\u5fc3\u95ee\u9898<\/p>\n<p id=\"1.3%20%E5%90%8C%E6%AD%A5%E7%9A%84%E6%A0%B8%E5%BF%83%EF%BC%9A%E7%AD%89%E5%BE%85%E4%B8%8E%E5%94%A4%E9%86%92-toc\" style=\"margin-left:40px\">1.3 \u540c\u6b65\u7684\u6838\u5fc3&#xff1a;\u7b49\u5f85\u4e0e\u5524\u9192<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%EF%BC%9A%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%E7%9A%84%20%E2%80%9C%E7%AD%89%E5%BE%85%20-%20%E5%94%A4%E9%86%92%E2%80%9D%20%E7%A5%9E%E5%99%A8-toc\" style=\"margin-left:0px\">\u4e8c\u3001\u6761\u4ef6\u53d8\u91cf&#xff1a;\u7ebf\u7a0b\u540c\u6b65\u7684 \u201c\u7b49\u5f85 &#8211; \u5524\u9192\u201d \u795e\u5668<\/p>\n<p id=\"2.1%20%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E7%9A%84%E6%A0%B8%E5%BF%83%E7%89%B9%E6%80%A7-toc\" style=\"margin-left:40px\">2.1 \u6761\u4ef6\u53d8\u91cf\u7684\u6838\u5fc3\u7279\u6027<\/p>\n<p id=\"2.2%20%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E7%9A%84%E6%A0%B8%E5%BF%83%E6%8E%A5%E5%8F%A3-toc\" style=\"margin-left:40px\">2.2 \u6761\u4ef6\u53d8\u91cf\u7684\u6838\u5fc3\u63a5\u53e3<\/p>\n<p id=\"2.2.1%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F-toc\" style=\"margin-left:80px\">2.2.1 \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf<\/p>\n<p id=\"%E6%96%B9%E5%BC%8F%201%EF%BC%9A%E9%9D%99%E6%80%81%E5%88%86%E9%85%8D%EF%BC%88%E6%8E%A8%E8%8D%90%E7%94%A8%E4%BA%8E%E5%85%A8%E5%B1%80%20%2F%20%E9%9D%99%E6%80%81%E5%8F%98%E9%87%8F%EF%BC%89-toc\" style=\"margin-left:120px\">\u65b9\u5f0f 1&#xff1a;\u9759\u6001\u5206\u914d&#xff08;\u63a8\u8350\u7528\u4e8e\u5168\u5c40 \/ \u9759\u6001\u53d8\u91cf&#xff09;<\/p>\n<p id=\"%E6%96%B9%E5%BC%8F%202%EF%BC%9A%E5%8A%A8%E6%80%81%E5%88%86%E9%85%8D%EF%BC%88%E7%94%A8%E4%BA%8E%E5%B1%80%E9%83%A8%20%2F%20%E5%A0%86%E4%B8%8A%E5%8F%98%E9%87%8F%EF%BC%89-toc\" style=\"margin-left:120px\">\u65b9\u5f0f 2&#xff1a;\u52a8\u6001\u5206\u914d&#xff08;\u7528\u4e8e\u5c40\u90e8 \/ \u5806\u4e0a\u53d8\u91cf&#xff09;<\/p>\n<p id=\"2.2.2%20%E9%94%80%E6%AF%81%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F-toc\" style=\"margin-left:80px\">2.2.2 \u9500\u6bc1\u6761\u4ef6\u53d8\u91cf<\/p>\n<p id=\"2.2.3%20%E7%AD%89%E5%BE%85%E6%9D%A1%E4%BB%B6%E6%BB%A1%E8%B6%B3%EF%BC%88%E6%A0%B8%E5%BF%83%E6%8E%A5%E5%8F%A3%EF%BC%89-toc\" style=\"margin-left:80px\">2.2.3 \u7b49\u5f85\u6761\u4ef6\u6ee1\u8db3&#xff08;\u6838\u5fc3\u63a5\u53e3&#xff09;<\/p>\n<p id=\"2.2.4%20%E5%94%A4%E9%86%92%E7%AD%89%E5%BE%85%E7%9A%84%E7%BA%BF%E7%A8%8B-toc\" style=\"margin-left:80px\">2.2.4 \u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b<\/p>\n<p id=\"%E5%94%A4%E9%86%92%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%EF%BC%9Apthread_cond_signal-toc\" style=\"margin-left:120px\">\u5524\u9192\u4e00\u4e2a\u7ebf\u7a0b&#xff1a;pthread_cond_signal<\/p>\n<p id=\"%E5%94%A4%E9%86%92%E6%89%80%E6%9C%89%E7%BA%BF%E7%A8%8B%EF%BC%9Apthread_cond_broadcast-toc\" style=\"margin-left:120px\">\u5524\u9192\u6240\u6709\u7ebf\u7a0b&#xff1a;pthread_cond_broadcast<\/p>\n<p id=\"2.3%20%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8%EF%BC%9A%E7%AE%80%E5%8D%95%E7%9A%84%E7%AD%89%E5%BE%85%20-%20%E5%94%A4%E9%86%92%E6%A1%88%E4%BE%8B-toc\" style=\"margin-left:40px\">2.3 \u6761\u4ef6\u53d8\u91cf\u5feb\u901f\u5165\u95e8&#xff1a;\u7b80\u5355\u7684\u7b49\u5f85 &#8211; \u5524\u9192\u6848\u4f8b<\/p>\n<p id=\"2.3.1%20%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:80px\">2.3.1 \u4ee3\u7801\u5b9e\u73b0<\/p>\n<p id=\"2.3.2%20%E7%BC%96%E8%AF%91%E8%BF%90%E8%A1%8C-toc\" style=\"margin-left:80px\">2.3.2 \u7f16\u8bd1\u8fd0\u884c<\/p>\n<p id=\"2.3.3%20%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-toc\" style=\"margin-left:80px\">2.3.3 \u8fd0\u884c\u7ed3\u679c\u5206\u6790<\/p>\n<p id=\"2.4%20%E4%B8%BA%E4%BB%80%E4%B9%88%20pthread_cond_wait%20%E5%BF%85%E9%A1%BB%E9%85%8D%E5%90%88%E4%BA%92%E6%96%A5%E9%87%8F%EF%BC%9F-toc\" style=\"margin-left:40px\">2.4 \u4e3a\u4ec0\u4e48 pthread_cond_wait \u5fc5\u987b\u914d\u5408\u4e92\u65a5\u91cf&#xff1f;<\/p>\n<p id=\"2.4.1%20%E6%A0%B8%E5%BF%83%E5%8E%9F%E5%9B%A0%201%EF%BC%9A%E9%81%BF%E5%85%8D%E5%94%A4%E9%86%92%E4%BF%A1%E5%8F%B7%20%E2%80%9C%E4%B8%A2%E5%A4%B1%E2%80%9D-toc\" style=\"margin-left:80px\">2.4.1 \u6838\u5fc3\u539f\u56e0 1&#xff1a;\u907f\u514d\u5524\u9192\u4fe1\u53f7 \u201c\u4e22\u5931\u201d<\/p>\n<p id=\"2.4.2%20%E6%A0%B8%E5%BF%83%E5%8E%9F%E5%9B%A0%202%EF%BC%9A%E4%BF%9D%E8%AF%81%E5%85%B1%E4%BA%AB%E8%B5%84%E6%BA%90%E7%9A%84%E8%AE%BF%E9%97%AE%E5%AE%89%E5%85%A8-toc\" style=\"margin-left:80px\">2.4.2 \u6838\u5fc3\u539f\u56e0 2&#xff1a;\u4fdd\u8bc1\u5171\u4eab\u8d44\u6e90\u7684\u8bbf\u95ee\u5b89\u5168<\/p>\n<p id=\"2.5%20%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E7%9A%84%E4%BD%BF%E7%94%A8%E8%A7%84%E8%8C%83%EF%BC%9A%E7%94%A8%20while%20%E5%88%A4%E6%96%AD%E6%9D%A1%E4%BB%B6%EF%BC%8C%E8%80%8C%E9%9D%9E%20if-toc\" style=\"margin-left:40px\">2.5 \u6761\u4ef6\u53d8\u91cf\u7684\u4f7f\u7528\u89c4\u8303&#xff1a;\u7528 while \u5224\u65ad\u6761\u4ef6&#xff0c;\u800c\u975e if<\/p>\n<p id=\"2.5.1%20%E4%BB%80%E4%B9%88%E6%98%AF%E4%BC%AA%E5%94%A4%E9%86%92%EF%BC%9F-toc\" style=\"margin-left:80px\">2.5.1 \u4ec0\u4e48\u662f\u4f2a\u5524\u9192&#xff1f;<\/p>\n<p id=\"2.5.2%20%E6%AD%A3%E7%A1%AE%E7%9A%84%E4%BD%BF%E7%94%A8%E6%A8%A1%E6%9D%BF%EF%BC%88%E5%BF%85%E8%AE%B0%EF%BC%89-toc\" style=\"margin-left:80px\">2.5.2 \u6b63\u786e\u7684\u4f7f\u7528\u6a21\u677f&#xff08;\u5fc5\u8bb0&#xff09;<\/p>\n<p id=\"%E6%A8%A1%E6%9D%BF%201%EF%BC%9A%E7%AD%89%E5%BE%85%E6%9D%A1%E4%BB%B6%E7%9A%84%E7%BA%BF%E7%A8%8B%EF%BC%88%E5%A6%82%E6%B6%88%E8%B4%B9%E8%80%85%EF%BC%89-toc\" style=\"margin-left:120px\">\u6a21\u677f 1&#xff1a;\u7b49\u5f85\u6761\u4ef6\u7684\u7ebf\u7a0b&#xff08;\u5982\u6d88\u8d39\u8005&#xff09;<\/p>\n<p id=\"%E6%A8%A1%E6%9D%BF%202%EF%BC%9A%E5%8F%91%E9%80%81%E4%BF%A1%E5%8F%B7%E7%9A%84%E7%BA%BF%E7%A8%8B%EF%BC%88%E5%A6%82%E7%94%9F%E4%BA%A7%E8%80%85%EF%BC%89-toc\" style=\"margin-left:120px\">\u6a21\u677f 2&#xff1a;\u53d1\u9001\u4fe1\u53f7\u7684\u7ebf\u7a0b&#xff08;\u5982\u751f\u4ea7\u8005&#xff09;<\/p>\n<p id=\"2.6%20%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E7%9A%84%20C%2B%2B%20%E5%B0%81%E8%A3%85%EF%BC%9ARAII%20%E9%A3%8E%E6%A0%BC%E6%9B%B4%E4%BC%98%E9%9B%85-toc\" style=\"margin-left:40px\">2.6 \u6761\u4ef6\u53d8\u91cf\u7684 C&#043;&#043; \u5c01\u88c5&#xff1a;RAII \u98ce\u683c\u66f4\u4f18\u96c5<\/p>\n<p id=\"2.6.1%20%E5%B0%81%E8%A3%85%E4%BB%A3%E7%A0%81%EF%BC%9ACond.hpp-toc\" style=\"margin-left:80px\">2.6.1 \u5c01\u88c5\u4ee3\u7801&#xff1a;Cond.hpp<\/p>\n<p id=\"2.6.2%20%E5%B0%81%E8%A3%85%E4%BB%A3%E7%A0%81%E8%A7%A3%E6%9E%90-toc\" style=\"margin-left:80px\">2.6.2 \u5c01\u88c5\u4ee3\u7801\u89e3\u6790<\/p>\n<p id=\"2.6.3%20%E5%B0%81%E8%A3%85%E5%90%8E%E7%9A%84%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B-toc\" style=\"margin-left:80px\">2.6.3 \u5c01\u88c5\u540e\u7684\u4f7f\u7528\u793a\u4f8b<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E7%94%9F%E4%BA%A7%E8%80%85%E6%B6%88%E8%B4%B9%E8%80%85%E6%A8%A1%E5%9E%8B%EF%BC%9A%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%E7%9A%84%E7%BB%8F%E5%85%B8%E5%AE%9E%E6%88%98-toc\" style=\"margin-left:0px\">\u4e09\u3001\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b&#xff1a;\u7ebf\u7a0b\u540c\u6b65\u7684\u7ecf\u5178\u5b9e\u6218<\/p>\n<p id=\"3.1%20%E7%94%9F%E4%BA%A7%E8%80%85%E6%B6%88%E8%B4%B9%E8%80%85%E6%A8%A1%E5%9E%8B%E7%9A%84%20%E2%80%9C321%E2%80%9D%20%E5%8E%9F%E5%88%99%EF%BC%88%E5%BF%85%E8%AE%B0%EF%BC%89-toc\" style=\"margin-left:40px\">3.1 \u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u7684 \u201c321\u201d \u539f\u5219&#xff08;\u5fc5\u8bb0&#xff09;<\/p>\n<p id=\"3%20%E7%A7%8D%E5%85%B3%E7%B3%BB%E8%AF%A6%E8%A7%A3%EF%BC%9A-toc\" style=\"margin-left:80px\">3 \u79cd\u5173\u7cfb\u8be6\u89e3&#xff1a;<\/p>\n<p id=\"3.2%20%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E7%94%9F%E4%BA%A7%E8%80%85%E6%B6%88%E8%B4%B9%E8%80%85%E6%A8%A1%E5%9E%8B%EF%BC%9F-toc\" style=\"margin-left:40px\">3.2 \u4e3a\u4ec0\u4e48\u9700\u8981\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b&#xff1f;<\/p>\n<p id=\"3.3%20%E5%9F%BA%E4%BA%8E%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E7%9A%84%E7%94%9F%E4%BA%A7%E8%80%85%E6%B6%88%E8%B4%B9%E8%80%85%E6%A8%A1%E5%9E%8B%EF%BC%88%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E5%AE%9E%E7%8E%B0%EF%BC%89-toc\" style=\"margin-left:40px\">3.3 \u57fa\u4e8e\u963b\u585e\u961f\u5217\u7684\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b&#xff08;\u6761\u4ef6\u53d8\u91cf\u5b9e\u73b0&#xff09;<\/p>\n<p id=\"3.3.1%20%E5%AE%9E%E7%8E%B0%E6%80%9D%E8%B7%AF-toc\" style=\"margin-left:80px\">3.3.1 \u5b9e\u73b0\u601d\u8def<\/p>\n<p id=\"3.3.2%20%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E5%AE%9E%E7%8E%B0%EF%BC%9ABlockQueue.hpp%EF%BC%88%E6%A8%A1%E6%9D%BF%E7%B1%BB%EF%BC%89-toc\" style=\"margin-left:80px\">3.3.2 \u963b\u585e\u961f\u5217\u5b9e\u73b0&#xff1a;BlockQueue.hpp&#xff08;\u6a21\u677f\u7c7b&#xff09;<\/p>\n<p id=\"3.3.3%20%E7%94%9F%E4%BA%A7%E8%80%85%E6%B6%88%E8%B4%B9%E8%80%85%E6%A8%A1%E5%9E%8B%E6%B5%8B%E8%AF%95%E4%BB%A3%E7%A0%81%EF%BC%9Amain.cpp-toc\" style=\"margin-left:80px\">3.3.3 \u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u6d4b\u8bd5\u4ee3\u7801&#xff1a;main.cpp<\/p>\n<p id=\"3.3.4%20%E7%BC%96%E8%AF%91%E8%BF%90%E8%A1%8C%E4%B8%8E%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-toc\" style=\"margin-left:80px\">3.3.4 \u7f16\u8bd1\u8fd0\u884c\u4e0e\u7ed3\u679c\u5206\u6790<\/p>\n<p id=\"3.4%20%E6%A8%A1%E5%9E%8B%E6%89%A9%E5%B1%95%EF%BC%9A%E6%94%AF%E6%8C%81%E8%87%AA%E5%AE%9A%E4%B9%89%E4%BB%BB%E5%8A%A1%E7%B1%BB%E5%9E%8B-toc\" style=\"margin-left:40px\">3.4 \u6a21\u578b\u6269\u5c55&#xff1a;\u652f\u6301\u81ea\u5b9a\u4e49\u4efb\u52a1\u7c7b\u578b<\/p>\n<p id=\"3.4.1%20%E8%87%AA%E5%AE%9A%E4%B9%89%E4%BB%BB%E5%8A%A1%E7%B1%BB%E5%9E%8B%EF%BC%9ATask.hpp-toc\" style=\"margin-left:80px\">3.4.1 \u81ea\u5b9a\u4e49\u4efb\u52a1\u7c7b\u578b&#xff1a;Task.hpp<\/p>\n<p id=\"3.4.2%20%E6%B5%8B%E8%AF%95%E4%BB%A3%E7%A0%81%EF%BC%9Amain_task.cpp-toc\" style=\"margin-left:80px\">3.4.2 \u6d4b\u8bd5\u4ee3\u7801&#xff1a;main_task.cpp<\/p>\n<p id=\"3.4.3%20%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C-toc\" style=\"margin-left:80px\">3.4.3 \u8fd0\u884c\u7ed3\u679c<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E4%B8%8E%E9%81%BF%E5%9D%91%E6%8C%87%E5%8D%97-toc\" style=\"margin-left:0px\">\u56db\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u907f\u5751\u6307\u5357<\/p>\n<p id=\"4.1%20%E5%9D%91%201%EF%BC%9A%E7%94%A8%20if%20%E5%88%A4%E6%96%AD%E6%9D%A1%E4%BB%B6%EF%BC%8C%E8%80%8C%E9%9D%9E%20while-toc\" style=\"margin-left:40px\">4.1 \u5751 1&#xff1a;\u7528 if \u5224\u65ad\u6761\u4ef6&#xff0c;\u800c\u975e while<\/p>\n<p id=\"4.2%20%E5%9D%91%202%EF%BC%9A%E5%BF%98%E8%AE%B0%E8%A7%A3%E9%94%81%E6%88%96%E8%A7%A3%E9%94%81%E6%97%B6%E6%9C%BA%E9%94%99%E8%AF%AF-toc\" style=\"margin-left:40px\">4.2 \u5751 2&#xff1a;\u5fd8\u8bb0\u89e3\u9501\u6216\u89e3\u9501\u65f6\u673a\u9519\u8bef<\/p>\n<p id=\"4.3%20%E5%9D%91%203%EF%BC%9A%E5%94%A4%E9%86%92%E5%87%BD%E6%95%B0%E4%BD%BF%E7%94%A8%E4%B8%8D%E5%BD%93-toc\" style=\"margin-left:40px\">4.3 \u5751 3&#xff1a;\u5524\u9192\u51fd\u6570\u4f7f\u7528\u4e0d\u5f53<\/p>\n<p id=\"4.4%20%E5%9D%91%204%EF%BC%9A%E9%98%9F%E5%88%97%E5%AE%B9%E9%87%8F%E8%AE%BE%E8%AE%A1%E4%B8%8D%E5%90%88%E7%90%86-toc\" style=\"margin-left:40px\">4.4 \u5751 4&#xff1a;\u961f\u5217\u5bb9\u91cf\u8bbe\u8ba1\u4e0d\u5408\u7406<\/p>\n<p id=\"4.5%20%E5%9D%91%205%EF%BC%9A%E7%BA%BF%E7%A8%8B%E9%80%80%E5%87%BA%E6%9C%BA%E5%88%B6%E7%BC%BA%E5%A4%B1-toc\" style=\"margin-left:40px\">4.5 \u5751 5&#xff1a;\u7ebf\u7a0b\u9000\u51fa\u673a\u5236\u7f3a\u5931<\/p>\n<p id=\"%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:0px\">\u603b\u7ed3<\/p>\n<hr id=\"hr-toc\" \/>\n<h2>\u4e00\u3001\u7ebf\u7a0b\u540c\u6b65\u6838\u5fc3\u6982\u5ff5&#xff1a;\u641e\u61c2 \u201c\u534f\u4f5c\u201d \u7684\u672c\u8d28<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728\u5b66\u4e60\u5177\u4f53\u5de5\u5177\u4e4b\u524d&#xff0c;\u6211\u4eec\u5fc5\u987b\u5148\u7406\u6e05\u51e0\u4e2a\u6838\u5fc3\u6982\u5ff5&#xff0c;\u8fd9\u662f\u7406\u89e3\u540e\u7eed\u6240\u6709\u5185\u5bb9\u7684\u57fa\u7840\u3002\u8fd9\u4e9b\u6982\u5ff5\u770b\u4f3c\u62bd\u8c61&#xff0c;\u4f46\u7ed3\u5408\u751f\u6d3b\u573a\u666f\u4e00\u770b\u5c31\u61c2\u3002<\/p>\n<h3 id=\"1.1%20%E4%BB%80%E4%B9%88%E6%98%AF%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%EF%BC%9F\">1.1 \u4ec0\u4e48\u662f\u7ebf\u7a0b\u540c\u6b65&#xff1f;<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7ebf\u7a0b\u540c\u6b65&#xff1a;\u5728\u4fdd\u8bc1\u6570\u636e\u5b89\u5168&#xff08;\u4e92\u65a5&#xff09;\u7684\u524d\u63d0\u4e0b&#xff0c;\u8ba9\u591a\u4e2a\u7ebf\u7a0b\u6309\u7167\u9884\u5148\u5b9a\u4e49\u7684\u987a\u5e8f\u8bbf\u95ee\u4e34\u754c\u8d44\u6e90&#xff0c;\u4ece\u800c\u907f\u514d\u7ebf\u7a0b\u9965\u997f\u3001\u65e0\u610f\u4e49\u8f6e\u8be2\u7b49\u95ee\u9898&#xff0c;\u5b9e\u73b0\u7ebf\u7a0b\u95f4\u7684\u9ad8\u6548\u534f\u4f5c\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u540c\u6b65\u7684\u6838\u5fc3\u662f \u201c\u987a\u5e8f\u201d&#xff0c;\u4e92\u65a5\u7684\u6838\u5fc3\u662f \u201c\u72ec\u5360\u201d&#xff1b;\u540c\u6b65\u662f\u5728\u4e92\u65a5\u7684\u57fa\u7840\u4e0a\u5b9e\u73b0\u7684 \u2014\u2014 \u6ca1\u6709\u4e92\u65a5\u7684\u540c\u6b65\u4f1a\u5bfc\u81f4\u6570\u636e\u7ade\u4e89&#xff0c;\u6ca1\u6709\u540c\u6b65\u7684\u4e92\u65a5\u53ea\u80fd\u4fdd\u8bc1\u6570\u636e\u5b89\u5168&#xff0c;\u5374\u65e0\u6cd5\u5b9e\u73b0\u7ebf\u7a0b\u95f4\u7684\u6709\u6548\u534f\u4f5c\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u751f\u6d3b\u6848\u4f8b&#xff1a;\u9910\u5385\u91cc\u7684\u53a8\u5e08&#xff08;\u751f\u4ea7\u8005&#xff09;\u548c\u670d\u52a1\u5458&#xff08;\u6d88\u8d39\u8005&#xff09;\u3002\u53a8\u5e08\u505a\u597d\u83dc&#xff08;\u751f\u4ea7\u6570\u636e&#xff09;\u540e&#xff0c;\u670d\u52a1\u5458\u624d\u80fd\u7aef\u8d70&#xff08;\u6d88\u8d39\u6570\u636e&#xff09;&#xff1b;\u5982\u679c\u83dc\u8fd8\u6ca1\u505a\u597d&#xff0c;\u670d\u52a1\u5458\u53ea\u80fd\u7b49\u5f85&#xff0c;\u4e0d\u80fd\u7a7a\u7740\u624b\u4e0a\u83dc&#xff1b;\u5982\u679c\u51fa\u83dc\u53e3\u6ee1\u4e86&#xff0c;\u53a8\u5e08\u53ea\u80fd\u7b49\u5f85&#xff0c;\u4e0d\u80fd\u628a\u83dc\u5806\u5728\u5730\u4e0a\u3002\u8fd9\u91cc\u7684 \u201c\u51fa\u83dc\u53e3\u201d \u5c31\u662f\u4e34\u754c\u8d44\u6e90&#xff0c;\u201c\u5148\u505a\u83dc\u540e\u4e0a\u83dc\u201d \u7684\u89c4\u5219\u5c31\u662f\u540c\u6b65\u3002<\/p>\n<h3 id=\"1.2%20%E7%AB%9E%E6%80%81%E6%9D%A1%E4%BB%B6%EF%BC%9A%E5%90%8C%E6%AD%A5%E8%A6%81%E8%A7%A3%E5%86%B3%E7%9A%84%E6%A0%B8%E5%BF%83%E9%97%AE%E9%A2%98\">1.2 \u7ade\u6001\u6761\u4ef6&#xff1a;\u540c\u6b65\u8981\u89e3\u51b3\u7684\u6838\u5fc3\u95ee\u9898<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7ade\u6001\u6761\u4ef6&#xff1a;\u7531\u4e8e\u7ebf\u7a0b\u6267\u884c\u7684\u65f6\u5e8f\u4e0d\u786e\u5b9a&#xff0c;\u5bfc\u81f4\u7a0b\u5e8f\u6267\u884c\u7ed3\u679c\u4e0d\u7b26\u5408\u9884\u671f\u7684\u95ee\u9898&#xff0c;\u8fd9\u662f\u7ebf\u7a0b\u540c\u6b65\u9700\u8981\u89e3\u51b3\u7684\u6838\u5fc3\u77db\u76fe\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7b80\u5355\u6765\u8bf4&#xff0c;\u5c31\u662f \u201c\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\u4e71\u4e86&#xff0c;\u7ed3\u679c\u5c31\u9519\u4e86\u201d\u3002\u6bd4\u5982&#xff1a;<\/p>\n<ul>\n<li>\u6d88\u8d39\u8005\u7ebf\u7a0b\u5148\u6267\u884c&#xff0c;\u53d1\u73b0\u961f\u5217\u4e3a\u7a7a&#xff0c;\u5374\u6ca1\u6709\u7b49\u5f85\u673a\u5236&#xff0c;\u53ea\u80fd\u4e0d\u65ad\u8f6e\u8be2 \u201c\u6709\u6ca1\u6709\u6570\u636e\u201d&#xff0c;\u6d6a\u8d39 CPU \u8d44\u6e90&#xff1b;<\/li>\n<li>\u751f\u4ea7\u8005\u7ebf\u7a0b\u751f\u4ea7\u901f\u5ea6\u592a\u5feb&#xff0c;\u961f\u5217\u6ee1\u4e86\u8fd8\u5728\u7ee7\u7eed\u751f\u4ea7&#xff0c;\u5bfc\u81f4\u6570\u636e\u6ea2\u51fa&#xff1b;<\/li>\n<li>\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u4fee\u6539\u5171\u4eab\u7684 \u201c\u7b49\u5f85\u6761\u4ef6\u201d&#xff08;\u6bd4\u5982\u961f\u5217\u5927\u5c0f&#xff09;&#xff0c;\u5bfc\u81f4\u6761\u4ef6\u5224\u65ad\u51fa\u9519\u3002<\/li>\n<\/ul>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7ade\u6001\u6761\u4ef6\u7684\u672c\u8d28\u662f \u201c\u5171\u4eab\u8d44\u6e90\u7684\u72b6\u6001\u53d8\u5316\u4e0e\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\u4e0d\u5339\u914d\u201d&#xff0c;\u800c\u7ebf\u7a0b\u540c\u6b65\u5c31\u662f\u901a\u8fc7 \u201c\u7b49\u5f85 &#8211; \u5524\u9192\u201d \u673a\u5236&#xff0c;\u8ba9\u7ebf\u7a0b\u7684\u6267\u884c\u987a\u5e8f\u9002\u914d\u5171\u4eab\u8d44\u6e90\u7684\u72b6\u6001\u53d8\u5316\u3002<\/p>\n<h3 id=\"1.3%20%E5%90%8C%E6%AD%A5%E7%9A%84%E6%A0%B8%E5%BF%83%EF%BC%9A%E7%AD%89%E5%BE%85%E4%B8%8E%E5%94%A4%E9%86%92\">1.3 \u540c\u6b65\u7684\u6838\u5fc3&#xff1a;\u7b49\u5f85\u4e0e\u5524\u9192<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7ebf\u7a0b\u540c\u6b65\u7684\u672c\u8d28\u7684\u662f\u89e3\u51b3 \u201c\u7b49\u5f85 &#8211; \u5524\u9192\u201d \u95ee\u9898&#xff1a;<\/p>\n<ul>\n<li>\u5f53\u7ebf\u7a0b\u7684\u6267\u884c\u6761\u4ef6\u4e0d\u6ee1\u8db3\u65f6&#xff08;\u5982\u961f\u5217\u4e3a\u7a7a\u3001\u961f\u5217\u6ee1&#xff09;&#xff0c;\u8ba9\u7ebf\u7a0b\u8fdb\u5165\u963b\u585e\u7b49\u5f85\u72b6\u6001&#xff0c;\u4e3b\u52a8\u91ca\u653e CPU \u8d44\u6e90&#xff0c;\u907f\u514d\u65e0\u610f\u4e49\u8f6e\u8be2&#xff1b;<\/li>\n<li>\u5f53\u5176\u4ed6\u7ebf\u7a0b\u4fee\u6539\u4e86\u5171\u4eab\u8d44\u6e90&#xff0c;\u4f7f\u6761\u4ef6\u6ee1\u8db3\u65f6&#xff08;\u5982\u751f\u4ea7\u8005\u751f\u4ea7\u4e86\u6570\u636e\u3001\u6d88\u8d39\u8005\u6d88\u8d39\u4e86\u6570\u636e&#xff09;&#xff0c;\u7531\u8be5\u7ebf\u7a0b\u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b&#xff0c;\u8ba9\u5176\u7ee7\u7eed\u6267\u884c\u3002<\/li>\n<\/ul>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728 Linux \u4e0b&#xff0c;\u5b9e\u73b0 \u201c\u7b49\u5f85 &#8211; \u5524\u9192\u201d \u7684\u6838\u5fc3\u5de5\u5177\u662f<span style=\"color:#956fe7\">\u6761\u4ef6\u53d8\u91cf&#xff08;pthread_cond_t&#xff09;<\/span>&#xff0c;\u5b83\u5fc5\u987b\u4e0e\u4e92\u65a5\u91cf\u914d\u5408\u4f7f\u7528&#xff0c;\u624d\u80fd\u5b89\u5168\u5730\u5b9e\u73b0\u7ebf\u7a0b\u540c\u6b65\u3002<\/p>\n<\/p>\n<h2 id=\"%E4%BA%8C%E3%80%81%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%EF%BC%9A%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%E7%9A%84%20%E2%80%9C%E7%AD%89%E5%BE%85%20-%20%E5%94%A4%E9%86%92%E2%80%9D%20%E7%A5%9E%E5%99%A8\">\u4e8c\u3001\u6761\u4ef6\u53d8\u91cf&#xff1a;\u7ebf\u7a0b\u540c\u6b65\u7684 \u201c\u7b49\u5f85 &#8211; \u5524\u9192\u201d \u795e\u5668<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6761\u4ef6\u53d8\u91cf\u662f POSIX \u7ebf\u7a0b\u5e93\u63d0\u4f9b\u7684\u6838\u5fc3\u540c\u6b65\u5de5\u5177&#xff0c;\u4e13\u95e8\u7528\u4e8e\u5b9e\u73b0\u7ebf\u7a0b\u95f4\u7684 \u201c\u7b49\u5f85 &#8211; \u5524\u9192\u201d \u673a\u5236\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u7ebf\u7a0b\u5728\u6761\u4ef6\u4e0d\u6ee1\u8db3\u65f6&#xff0c;\u91ca\u653e\u6301\u6709\u7684\u4e92\u65a5\u91cf&#xff0c;\u8fdb\u5165\u963b\u585e\u7b49\u5f85&#xff1b;\u5f53\u5176\u4ed6\u7ebf\u7a0b\u4fee\u6539\u4e86\u5171\u4eab\u8d44\u6e90&#xff0c;\u4f7f\u6761\u4ef6\u6ee1\u8db3\u65f6&#xff0c;\u5524\u9192\u7b49\u5f85\u5728\u8be5\u6761\u4ef6\u53d8\u91cf\u4e0a\u7684\u7ebf\u7a0b&#xff0c;\u8ba9\u5176\u91cd\u65b0\u7ade\u4e89\u4e92\u65a5\u91cf\u5e76\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n<h3 id=\"2.1%20%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E7%9A%84%E6%A0%B8%E5%BF%83%E7%89%B9%E6%80%A7\">2.1 \u6761\u4ef6\u53d8\u91cf\u7684\u6838\u5fc3\u7279\u6027<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6761\u4ef6\u53d8\u91cf\u672c\u8eab\u4e0d\u5177\u5907\u4e92\u65a5\u529f\u80fd&#xff0c;\u5b83\u5fc5\u987b\u4e0e\u4e92\u65a5\u91cf\u914d\u5408\u4f7f\u7528&#xff0c;\u539f\u56e0\u6709\u4e8c&#xff1a;<\/p>\n<li>\u5171\u4eab\u8d44\u6e90&#xff08;\u5982\u961f\u5217\u3001\u8ba1\u6570\u5668&#xff09;\u7684\u8bbf\u95ee\u9700\u8981\u4e92\u65a5\u4fdd\u62a4&#xff0c;\u907f\u514d\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u4fee\u6539&#xff1b;<\/li>\n<li>\u6761\u4ef6\u53d8\u91cf\u7684 \u201c\u7b49\u5f85\u201d \u64cd\u4f5c\u9700\u8981\u4e0e \u201c\u89e3\u9501\u201d \u64cd\u4f5c\u539f\u5b50\u5316&#xff0c;\u907f\u514d\u5524\u9192\u4fe1\u53f7\u4e22\u5931\u3002<\/li>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6761\u4ef6\u53d8\u91cf\u7684\u6838\u5fc3\u4ef7\u503c\u5728\u4e8e&#xff1a;\u8ba9\u7ebf\u7a0b\u5728\u6761\u4ef6\u4e0d\u6ee1\u8db3\u65f6\u4e3b\u52a8\u653e\u5f03 CPU&#xff0c;\u800c\u4e0d\u662f\u65e0\u610f\u4e49\u5730\u8f6e\u8be2&#xff0c;\u4ece\u800c\u63d0\u9ad8 CPU \u5229\u7528\u7387\u3002<\/p>\n<h3 id=\"2.2%20%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E7%9A%84%E6%A0%B8%E5%BF%83%E6%8E%A5%E5%8F%A3\">2.2 \u6761\u4ef6\u53d8\u91cf\u7684\u6838\u5fc3\u63a5\u53e3<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6761\u4ef6\u53d8\u91cf\u7684\u6838\u5fc3\u7c7b\u578b\u662f<span style=\"color:#956fe7\">pthread_cond_t<\/span>&#xff0c;\u6240\u6709\u64cd\u4f5c\u90fd\u56f4\u7ed5\u8fd9\u4e2a\u7c7b\u578b\u5c55\u5f00&#xff0c;\u6838\u5fc3\u63a5\u53e3\u5305\u62ec\u521d\u59cb\u5316\u3001\u9500\u6bc1\u3001\u7b49\u5f85\u3001\u5524\u9192&#xff0c;\u5747\u5728<span style=\"color:#956fe7\">&lt;pthread.h&gt;<\/span>\u5934\u6587\u4ef6\u4e2d\u58f0\u660e\u3002<\/p>\n<h4 id=\"2.2.1%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F\">2.2.1 \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u548c\u4e92\u65a5\u91cf\u7c7b\u4f3c&#xff0c;\u6761\u4ef6\u53d8\u91cf\u7684\u521d\u59cb\u5316\u6709\u9759\u6001\u5206\u914d\u548c\u52a8\u6001\u5206\u914d\u4e24\u79cd\u65b9\u5f0f&#xff0c;\u9002\u7528\u4e8e\u4e0d\u540c\u573a\u666f\u3002<\/p>\n<h5 id=\"%E6%96%B9%E5%BC%8F%201%EF%BC%9A%E9%9D%99%E6%80%81%E5%88%86%E9%85%8D%EF%BC%88%E6%8E%A8%E8%8D%90%E7%94%A8%E4%BA%8E%E5%85%A8%E5%B1%80%20%2F%20%E9%9D%99%E6%80%81%E5%8F%98%E9%87%8F%EF%BC%89\">\u65b9\u5f0f 1&#xff1a;\u9759\u6001\u5206\u914d&#xff08;\u63a8\u8350\u7528\u4e8e\u5168\u5c40 \/ \u9759\u6001\u53d8\u91cf&#xff09;<\/h5>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4f7f\u7528\u5b8f<span style=\"color:#956fe7\">PTHREAD_COND_INITIALIZER<\/span>\u76f4\u63a5\u521d\u59cb\u5316&#xff0c;\u7b80\u5355\u9ad8\u6548&#xff0c;\u65e0\u9700\u624b\u52a8\u9500\u6bc1&#xff1a;<\/p>\n<p>\/\/ \u9759\u6001\u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf<br \/>\npthread_cond_t cond &#061; PTHREAD_COND_INITIALIZER;<br \/>\n\/\/ \u914d\u5408\u9759\u6001\u521d\u59cb\u5316\u7684\u4e92\u65a5\u91cf<br \/>\npthread_mutex_t mutex &#061; PTHREAD_MUTEX_INITIALIZER;<\/p>\n<h5 id=\"%E6%96%B9%E5%BC%8F%202%EF%BC%9A%E5%8A%A8%E6%80%81%E5%88%86%E9%85%8D%EF%BC%88%E7%94%A8%E4%BA%8E%E5%B1%80%E9%83%A8%20%2F%20%E5%A0%86%E4%B8%8A%E5%8F%98%E9%87%8F%EF%BC%89\">\u65b9\u5f0f 2&#xff1a;\u52a8\u6001\u5206\u914d&#xff08;\u7528\u4e8e\u5c40\u90e8 \/ \u5806\u4e0a\u53d8\u91cf&#xff09;<\/h5>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4f7f\u7528<span style=\"color:#956fe7\">pthread_cond_init<\/span>\u51fd\u6570\u521d\u59cb\u5316&#xff0c;\u652f\u6301\u81ea\u5b9a\u4e49\u5c5e\u6027&#xff0c;\u4f7f\u7528\u540e\u9700\u8981\u624b\u52a8\u9500\u6bc1&#xff1a;<\/p>\n<p>int pthread_cond_init(pthread_cond_t *restrict cond, const pthread_condattr_t *restrict attr);<\/p>\n<ul>\n<li>\u53c2\u6570\u8bf4\u660e&#xff1a;\n<ul>\n<li><span style=\"color:#956fe7\">cond<\/span>&#xff1a;\u6307\u5411\u8981\u521d\u59cb\u5316\u7684\u6761\u4ef6\u53d8\u91cf\u5bf9\u8c61\u7684\u6307\u9488&#xff1b;<\/li>\n<li><span style=\"color:#956fe7\">attr<\/span>&#xff1a;\u6761\u4ef6\u53d8\u91cf\u7684\u5c5e\u6027&#xff0c;\u4e00\u822c\u8bbe\u4e3aNULL&#xff08;\u4f7f\u7528\u9ed8\u8ba4\u5c5e\u6027&#xff09;&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>\u8fd4\u56de\u503c&#xff1a;\u6210\u529f\u8fd4\u56de 0&#xff0c;\u5931\u8d25\u8fd4\u56de\u5bf9\u5e94\u7684\u9519\u8bef\u53f7&#xff08;\u5982EINVAL\u8868\u793a\u53c2\u6570\u65e0\u6548&#xff09;\u3002<\/li>\n<\/ul>\n<h4 id=\"2.2.2%20%E9%94%80%E6%AF%81%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F\">2.2.2 \u9500\u6bc1\u6761\u4ef6\u53d8\u91cf<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6761\u4ef6\u53d8\u91cf\u4f7f\u7528\u5b8c\u6210\u540e\u9700\u8981\u9500\u6bc1&#xff0c;\u91ca\u653e\u7cfb\u7edf\u8d44\u6e90&#xff0c;\u6838\u5fc3\u51fd\u6570\u662f<span style=\"color:#fe2c24\"><span style=\"background-color:#fbd4d0\">pthread_cond_destroy<\/span><\/span>&#xff1a;<\/p>\n<p>int pthread_cond_destroy(pthread_cond_t *cond);<\/p>\n<ul>\n<li>\u53c2\u6570\u8bf4\u660e&#xff1a;<span style=\"color:#956fe7\">cond<\/span>\u6307\u5411\u8981\u9500\u6bc1\u7684\u6761\u4ef6\u53d8\u91cf\u5bf9\u8c61&#xff1b;<\/li>\n<li>\u8fd4\u56de\u503c&#xff1a;\u6210\u529f\u8fd4\u56de 0&#xff0c;\u5931\u8d25\u8fd4\u56de\u9519\u8bef\u53f7&#xff1b;<\/li>\n<li>\u6ce8\u610f\u4e8b\u9879&#xff1a;\n<li>\u9759\u6001\u521d\u59cb\u5316\u7684\u6761\u4ef6\u53d8\u91cf&#xff08;<span style=\"color:#956fe7\">PTHREAD_COND_INITIALIZER<\/span>&#xff09;\u65e0\u9700\u624b\u52a8\u9500\u6bc1&#xff1b;<\/li>\n<li>\u4e0d\u8981\u9500\u6bc1\u6709\u7ebf\u7a0b\u6b63\u5728\u7b49\u5f85\u7684\u6761\u4ef6\u53d8\u91cf&#xff0c;\u5426\u5219\u4f1a\u5bfc\u81f4\u672a\u5b9a\u4e49\u884c\u4e3a&#xff1b;<\/li>\n<li>\u5df2\u7ecf\u9500\u6bc1\u7684\u6761\u4ef6\u53d8\u91cf&#xff0c;\u4e0d\u80fd\u518d\u88ab\u5176\u4ed6\u7ebf\u7a0b\u4f7f\u7528\u3002<\/li>\n<\/li>\n<\/ul>\n<h4 id=\"2.2.3%20%E7%AD%89%E5%BE%85%E6%9D%A1%E4%BB%B6%E6%BB%A1%E8%B6%B3%EF%BC%88%E6%A0%B8%E5%BF%83%E6%8E%A5%E5%8F%A3%EF%BC%89\">2.2.3 \u7b49\u5f85\u6761\u4ef6\u6ee1\u8db3&#xff08;\u6838\u5fc3\u63a5\u53e3&#xff09;<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8ba9\u7ebf\u7a0b\u5728\u6307\u5b9a\u7684\u6761\u4ef6\u53d8\u91cf\u4e0a\u963b\u585e\u7b49\u5f85&#xff0c;\u76f4\u5230\u88ab\u5524\u9192&#xff0c;\u6838\u5fc3\u51fd\u6570\u662f<span style=\"color:#fe2c24\"><span style=\"background-color:#fbd4d0\">pthread_cond_wait<\/span><\/span>&#xff1a;<\/p>\n<p>int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex);<\/p>\n<ul>\n<li>\u53c2\u6570\u8bf4\u660e&#xff1a;\n<ul>\n<li><span style=\"color:#956fe7\">cond<\/span>&#xff1a;\u7ebf\u7a0b\u8981\u7b49\u5f85\u7684\u6761\u4ef6\u53d8\u91cf&#xff1b;<\/li>\n<li><span style=\"color:#956fe7\">mutex<\/span>&#xff1a;\u7ebf\u7a0b\u5f53\u524d\u6301\u6709\u7684\u4e92\u65a5\u91cf&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>\u8fd4\u56de\u503c&#xff1a;\u6210\u529f\u8fd4\u56de 0&#xff0c;\u5931\u8d25\u8fd4\u56de\u9519\u8bef\u53f7&#xff1b;<\/li>\n<li>\u4e09\u4e2a\u5173\u952e\u7279\u6027&#xff08;\u5fc5\u987b\u7262\u8bb0&#xff09;&#xff1a;\n<li>\u81ea\u52a8\u89e3\u9501&#xff1a;\u8c03\u7528\u51fd\u6570\u65f6&#xff0c;\u7ebf\u7a0b\u4f1a\u81ea\u52a8\u91ca\u653e\u6301\u6709\u7684\u4e92\u65a5\u91cf&#xff0c;\u8ba9\u5176\u4ed6\u7ebf\u7a0b\u6709\u673a\u4f1a\u4fee\u6539\u5171\u4eab\u8d44\u6e90&#xff1b;<\/li>\n<li>\u963b\u585e\u7b49\u5f85&#xff1a;\u7ebf\u7a0b\u8fdb\u5165\u963b\u585e\u72b6\u6001&#xff0c;\u4e0d\u5360\u7528 CPU \u8d44\u6e90&#xff0c;\u76f4\u5230\u88ab\u5176\u4ed6\u7ebf\u7a0b\u5524\u9192&#xff1b;<\/li>\n<li>\u91cd\u65b0\u52a0\u9501&#xff1a;\u7ebf\u7a0b\u88ab\u5524\u9192\u540e&#xff0c;\u4f1a\u91cd\u65b0\u7ade\u4e89\u4e92\u65a5\u91cf&#xff0c;\u53ea\u6709\u7ade\u4e89\u6210\u529f\u540e&#xff0c;\u624d\u4f1a\u4ece<span style=\"color:#956fe7\">pthread_cond_wait<\/span>\u8fd4\u56de&#xff0c;\u7ee7\u7eed\u6267\u884c\u540e\u7eed\u4ee3\u7801\u3002<\/li>\n<\/li>\n<\/ul>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7b80\u5355\u6765\u8bf4&#xff0c;<span style=\"color:#956fe7\">pthread_cond_wait<\/span>\u5b8c\u6210\u4e86 \u201c\u89e3\u9501\u2192\u7b49\u5f85\u2192\u88ab\u5524\u9192\u2192\u91cd\u65b0\u52a0\u9501\u201d \u7684\u539f\u5b50\u64cd\u4f5c&#xff0c;\u8fd9\u662f\u4fdd\u8bc1\u540c\u6b65\u5b89\u5168\u7684\u6838\u5fc3\u3002<\/p>\n<h4 id=\"2.2.4%20%E5%94%A4%E9%86%92%E7%AD%89%E5%BE%85%E7%9A%84%E7%BA%BF%E7%A8%8B\">2.2.4 \u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0POSIX \u7ebf\u7a0b\u5e93\u63d0\u4f9b\u4e86\u4e24\u4e2a\u5524\u9192\u51fd\u6570&#xff0c;\u5206\u522b\u7528\u4e8e\u5524\u9192\u4e00\u4e2a\u7ebf\u7a0b\u548c\u6240\u6709\u7ebf\u7a0b&#xff0c;\u6ee1\u8db3\u4e0d\u540c\u7684\u540c\u6b65\u573a\u666f\u3002<\/p>\n<h5 id=\"%E5%94%A4%E9%86%92%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%EF%BC%9Apthread_cond_signal\">\u5524\u9192\u4e00\u4e2a\u7ebf\u7a0b&#xff1a;pthread_cond_signal<\/h5>\n<p>int pthread_cond_signal(pthread_cond_t *cond);<\/p>\n<ul>\n<li>\u529f\u80fd&#xff1a;\u5524\u9192\u7b49\u5f85\u5728\u8be5\u6761\u4ef6\u53d8\u91cf\u4e0a\u7684\u4efb\u610f\u4e00\u4e2a\u7ebf\u7a0b&#xff08;\u7531\u64cd\u4f5c\u7cfb\u7edf\u8c03\u5ea6\u9009\u62e9&#xff09;&#xff0c;\u5176\u4ed6\u7ebf\u7a0b\u4ecd\u5904\u4e8e\u963b\u585e\u72b6\u6001&#xff1b;<\/li>\n<li>\u9002\u7528\u573a\u666f&#xff1a;\u4e00\u5bf9\u4e00\u540c\u6b65&#xff08;\u5982\u5355\u751f\u4ea7\u8005\u5355\u6d88\u8d39\u8005&#xff09;&#xff0c;\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u7ebf\u7a0b\u5524\u9192&#xff0c;\u63d0\u9ad8\u6548\u7387\u3002<\/li>\n<\/ul>\n<h5 id=\"%E5%94%A4%E9%86%92%E6%89%80%E6%9C%89%E7%BA%BF%E7%A8%8B%EF%BC%9Apthread_cond_broadcast\">\u5524\u9192\u6240\u6709\u7ebf\u7a0b&#xff1a;pthread_cond_broadcast<\/h5>\n<p>int pthread_cond_broadcast(pthread_cond_t *cond);<\/p>\n<ul>\n<li>\u529f\u80fd&#xff1a;\u5524\u9192\u7b49\u5f85\u5728\u8be5\u6761\u4ef6\u53d8\u91cf\u4e0a\u7684\u6240\u6709\u7ebf\u7a0b&#xff0c;\u8ba9\u5b83\u4eec\u91cd\u65b0\u7ade\u4e89\u4e92\u65a5\u91cf&#xff1b;<\/li>\n<li>\u9002\u7528\u573a\u666f&#xff1a;\u4e00\u5bf9\u591a\u6216\u591a\u5bf9\u591a\u540c\u6b65&#xff08;\u5982\u591a\u751f\u4ea7\u8005\u591a\u6d88\u8d39\u8005&#xff09;&#xff0c;\u786e\u4fdd\u6240\u6709\u7b49\u5f85\u7684\u7ebf\u7a0b\u90fd\u80fd\u6536\u5230\u4fe1\u53f7\u3002<\/li>\n<\/ul>\n<h3 id=\"2.3%20%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8%EF%BC%9A%E7%AE%80%E5%8D%95%E7%9A%84%E7%AD%89%E5%BE%85%20-%20%E5%94%A4%E9%86%92%E6%A1%88%E4%BE%8B\">2.3 \u6761\u4ef6\u53d8\u91cf\u5feb\u901f\u5165\u95e8&#xff1a;\u7b80\u5355\u7684\u7b49\u5f85 &#8211; \u5524\u9192\u6848\u4f8b<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e3a\u4e86\u8ba9\u5927\u5bb6\u5feb\u901f\u7406\u89e3\u6761\u4ef6\u53d8\u91cf\u7684\u4f7f\u7528&#xff0c;\u6211\u4eec\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u6848\u4f8b&#xff1a;\u521b\u5efa 2 \u4e2a\u7b49\u5f85\u7ebf\u7a0b&#xff0c;\u4e3b\u7ebf\u7a0b\u6bcf\u9694 1 \u79d2\u5524\u9192\u5b83\u4eec&#xff0c;\u5206\u522b\u6d4b\u8bd5<span style=\"color:#956fe7\">signal<\/span>\u548c<span style=\"color:#956fe7\">broadcast<\/span>\u7684\u6548\u679c\u3002<\/p>\n<h4 id=\"2.3.1%20%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0\">2.3.1 \u4ee3\u7801\u5b9e\u73b0<\/h4>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;cstring&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;pthread.h&gt;<\/p>\n<p>\/\/ \u9759\u6001\u521d\u59cb\u5316\u4e92\u65a5\u91cf\u548c\u6761\u4ef6\u53d8\u91cf<br \/>\npthread_mutex_t mutex &#061; PTHREAD_MUTEX_INITIALIZER;<br \/>\npthread_cond_t cond &#061; PTHREAD_COND_INITIALIZER;<\/p>\n<p>\/\/ \u7ebf\u7a0b\u6267\u884c\u51fd\u6570&#xff1a;\u7b49\u5f85\u6761\u4ef6\u53d8\u91cf\u88ab\u5524\u9192<br \/>\nvoid *wait_thread(void *arg) {<br \/>\n    char *thread_name &#061; static_cast&lt;char*&gt;(arg);<br \/>\n    while (true) {<br \/>\n        \/\/ 1. \u52a0\u9501&#xff1a;\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\u524d\u5fc5\u987b\u4fdd\u8bc1\u4e92\u65a5<br \/>\n        pthread_mutex_lock(&amp;mutex);<\/p>\n<p>        \/\/ 2. \u7b49\u5f85\u6761\u4ef6\u53d8\u91cf&#xff1a;\u81ea\u52a8\u91ca\u653e\u4e92\u65a5\u91cf&#xff0c;\u88ab\u5524\u9192\u540e\u91cd\u65b0\u52a0\u9501<br \/>\n        std::cout &lt;&lt; thread_name &lt;&lt; &#034;&#xff1a;\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u8fdb\u5165\u7b49\u5f85&#8230;&#034; &lt;&lt; std::endl;<br \/>\n        pthread_cond_wait(&amp;cond, &amp;mutex);<\/p>\n<p>        \/\/ 3. \u88ab\u5524\u9192\u540e\u6267\u884c&#xff1a;\u6b64\u65f6\u5df2\u91cd\u65b0\u83b7\u5f97\u4e92\u65a5\u91cf<br \/>\n        std::cout &lt;&lt; thread_name &lt;&lt; &#034;&#xff1a;\u88ab\u5524\u9192&#xff0c;\u6267\u884c\u4efb\u52a1&#8230;&#034; &lt;&lt; std::endl;<\/p>\n<p>        \/\/ 4. \u89e3\u9501&#xff1a;\u91ca\u653e\u4e34\u754c\u8d44\u6e90<br \/>\n        pthread_mutex_unlock(&amp;mutex);<\/p>\n<p>        \/\/ \u6a21\u62df\u4efb\u52a1\u6267\u884c\u8017\u65f6<br \/>\n        sleep(1);<br \/>\n    }<br \/>\n    return nullptr;<br \/>\n}<\/p>\n<p>int main(void) {<br \/>\n    pthread_t t1, t2;<br \/>\n    \/\/ \u521b\u5efa\u4e24\u4e2a\u7b49\u5f85\u7ebf\u7a0b<br \/>\n    pthread_create(&amp;t1, NULL, wait_thread, (void*)&#034;\u7ebf\u7a0bA&#034;);<br \/>\n    pthread_create(&amp;t2, NULL, wait_thread, (void*)&#034;\u7ebf\u7a0bB&#034;);<\/p>\n<p>    \/\/ \u4e3b\u7ebf\u7a0b&#xff1a;\u6bcf\u96941\u79d2\u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b<br \/>\n    sleep(2); \/\/ \u786e\u4fdd\u4e24\u4e2a\u7ebf\u7a0b\u90fd\u5df2\u542f\u52a8\u5e76\u8fdb\u5165\u7b49\u5f85<br \/>\n    int count &#061; 0;<br \/>\n    while (count &lt; 3) {<br \/>\n        std::cout &lt;&lt; &#034;\\\\n\u4e3b\u7ebf\u7a0b&#xff1a;\u51c6\u5907\u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b&#xff08;\u7b2c&#034; &lt;&lt; count&#043;1 &lt;&lt; &#034;\u6b21&#xff09;&#034; &lt;&lt; std::endl;<\/p>\n<p>        \/\/ \u6d4b\u8bd51&#xff1a;\u5524\u9192\u4e00\u4e2a\u7ebf\u7a0b&#xff08;pthread_cond_signal&#xff09;<br \/>\n        \/\/ pthread_cond_signal(&amp;cond);<\/p>\n<p>        \/\/ \u6d4b\u8bd52&#xff1a;\u5524\u9192\u6240\u6709\u7ebf\u7a0b&#xff08;pthread_cond_broadcast&#xff09;<br \/>\n        pthread_cond_broadcast(&amp;cond);<\/p>\n<p>        sleep(2);<br \/>\n        count&#043;&#043;;<br \/>\n    }<\/p>\n<p>    \/\/ \u9500\u6bc1\u8d44\u6e90&#xff08;\u5b9e\u9645\u4e0d\u4f1a\u6267\u884c\u5230&#xff0c;\u8fd9\u91cc\u4ec5\u4f5c\u6f14\u793a&#xff09;<br \/>\n    pthread_cond_destroy(&amp;cond);<br \/>\n    pthread_mutex_destroy(&amp;mutex);<br \/>\n    return 0;<br \/>\n}<\/p>\n<h4 id=\"2.3.2%20%E7%BC%96%E8%AF%91%E8%BF%90%E8%A1%8C\">2.3.2 \u7f16\u8bd1\u8fd0\u884c<\/h4>\n<p># \u7f16\u8bd1&#xff1a;\u94fe\u63a5pthread\u5e93&#xff08;\u591a\u7ebf\u7a0b\u7f16\u7a0b\u5fc5\u5907&#xff09;<br \/>\ng&#043;&#043; cond_demo.cpp -o cond_demo -lpthread<br \/>\n# \u8fd0\u884c<br \/>\n.\/cond_demo<\/p>\n<h4 id=\"2.3.3%20%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90\">2.3.3 \u8fd0\u884c\u7ed3\u679c\u5206\u6790<\/h4>\n<ul>\n<li>\n<p>\u4f7f\u7528 pthread_cond_signal \u65f6&#xff1a;\u6bcf\u6b21\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u88ab\u5524\u9192&#xff08;\u7ebf\u7a0b A \u548c\u7ebf\u7a0b B \u4ea4\u66ff\u6267\u884c&#xff09;&#xff0c;\u8f93\u51fa\u5982\u4e0b&#xff1a;<\/p>\n<p> \u7ebf\u7a0bA&#xff1a;\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u8fdb\u5165\u7b49\u5f85&#8230;<br \/>\n\u7ebf\u7a0bB&#xff1a;\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u8fdb\u5165\u7b49\u5f85&#8230;<\/p>\n<p>\u4e3b\u7ebf\u7a0b&#xff1a;\u51c6\u5907\u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b&#xff08;\u7b2c1\u6b21&#xff09;<br \/>\n\u7ebf\u7a0bA&#xff1a;\u88ab\u5524\u9192&#xff0c;\u6267\u884c\u4efb\u52a1&#8230;<br \/>\n\u7ebf\u7a0bB&#xff1a;\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u8fdb\u5165\u7b49\u5f85&#8230;<\/p>\n<p>\u4e3b\u7ebf\u7a0b&#xff1a;\u51c6\u5907\u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b&#xff08;\u7b2c2\u6b21&#xff09;<br \/>\n\u7ebf\u7a0bB&#xff1a;\u88ab\u5524\u9192&#xff0c;\u6267\u884c\u4efb\u52a1&#8230;<br \/>\n\u7ebf\u7a0bA&#xff1a;\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u8fdb\u5165\u7b49\u5f85&#8230;\n <\/li>\n<li>\n<p>\u4f7f\u7528 pthread_cond_broadcast \u65f6&#xff1a;\u6bcf\u6b21\u4e24\u4e2a\u7ebf\u7a0b\u90fd\u88ab\u5524\u9192&#xff0c;\u8f93\u51fa\u5982\u4e0b&#xff1a;<\/p>\n<p> \u7ebf\u7a0bA&#xff1a;\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u8fdb\u5165\u7b49\u5f85&#8230;<br \/>\n\u7ebf\u7a0bB&#xff1a;\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u8fdb\u5165\u7b49\u5f85&#8230;<\/p>\n<p>\u4e3b\u7ebf\u7a0b&#xff1a;\u51c6\u5907\u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b&#xff08;\u7b2c1\u6b21&#xff09;<br \/>\n\u7ebf\u7a0bA&#xff1a;\u88ab\u5524\u9192&#xff0c;\u6267\u884c\u4efb\u52a1&#8230;<br \/>\n\u7ebf\u7a0bB&#xff1a;\u88ab\u5524\u9192&#xff0c;\u6267\u884c\u4efb\u52a1&#8230;<\/p>\n<p>\u4e3b\u7ebf\u7a0b&#xff1a;\u51c6\u5907\u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b&#xff08;\u7b2c2\u6b21&#xff09;<br \/>\n\u7ebf\u7a0bA&#xff1a;\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u8fdb\u5165\u7b49\u5f85&#8230;<br \/>\n\u7ebf\u7a0bB&#xff1a;\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u8fdb\u5165\u7b49\u5f85&#8230;<br \/>\n\u7ebf\u7a0bA&#xff1a;\u88ab\u5524\u9192&#xff0c;\u6267\u884c\u4efb\u52a1&#8230;<br \/>\n\u7ebf\u7a0bB&#xff1a;\u88ab\u5524\u9192&#xff0c;\u6267\u884c\u4efb\u52a1&#8230;\n <\/li>\n<\/ul>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fd9\u4e2a\u6848\u4f8b\u6e05\u6670\u5730\u5c55\u793a\u4e86\u6761\u4ef6\u53d8\u91cf\u7684 \u201c\u7b49\u5f85 &#8211; \u5524\u9192\u201d \u673a\u5236&#xff0c;\u6838\u5fc3\u8981\u70b9\u662f&#xff1a;\u7b49\u5f85\u524d\u5fc5\u987b\u52a0\u9501&#xff0c;\u5524\u9192\u540e\u5fc5\u987b\u89e3\u9501&#xff0c;\u4e14<span style=\"color:#fe2c24\"><span style=\"background-color:#fbd4d0\">pthread_cond_wait<\/span><\/span>\u5fc5\u987b\u4e0e\u4e92\u65a5\u91cf\u914d\u5408\u4f7f\u7528\u3002<\/p>\n<h3 id=\"2.4%20%E4%B8%BA%E4%BB%80%E4%B9%88%20pthread_cond_wait%20%E5%BF%85%E9%A1%BB%E9%85%8D%E5%90%88%E4%BA%92%E6%96%A5%E9%87%8F%EF%BC%9F\">2.4 \u4e3a\u4ec0\u4e48 pthread_cond_wait \u5fc5\u987b\u914d\u5408\u4e92\u65a5\u91cf&#xff1f;<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fd9\u662f\u9762\u8bd5\u548c\u5f00\u53d1\u4e2d\u7684\u9ad8\u9891\u95ee\u9898&#xff0c;\u4e5f\u662f\u7406\u89e3\u6761\u4ef6\u53d8\u91cf\u7684\u5173\u952e\u3002\u5f88\u591a\u4eba\u4f1a\u7591\u60d1&#xff1a;\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u5148\u89e3\u9501&#xff0c;\u518d\u8c03\u7528<span style=\"color:#fe2c24\"><span style=\"background-color:#fbd4d0\">pthread_cond_wait<\/span><\/span>&#xff1f;\u6211\u4eec\u4ece\u4e24\u4e2a\u6838\u5fc3\u89d2\u5ea6\u89e3\u7b54\u3002<\/p>\n<h4 id=\"2.4.1%20%E6%A0%B8%E5%BF%83%E5%8E%9F%E5%9B%A0%201%EF%BC%9A%E9%81%BF%E5%85%8D%E5%94%A4%E9%86%92%E4%BF%A1%E5%8F%B7%20%E2%80%9C%E4%B8%A2%E5%A4%B1%E2%80%9D\">2.4.1 \u6838\u5fc3\u539f\u56e0 1&#xff1a;\u907f\u514d\u5524\u9192\u4fe1\u53f7 \u201c\u4e22\u5931\u201d<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\u679c\u624b\u52a8\u8bbe\u8ba1 \u201c\u89e3\u9501\u2192\u7b49\u5f85\u201d \u7684\u903b\u8f91&#xff08;\u9519\u8bef\u5199\u6cd5&#xff09;&#xff1a;<\/p>\n<p>\/\/ \u9519\u8bef\u793a\u4f8b&#xff1a;\u89e3\u9501\u548c\u7b49\u5f85\u4e0d\u662f\u539f\u5b50\u64cd\u4f5c<br \/>\npthread_mutex_lock(&amp;mutex);<br \/>\nwhile (condition &#061;&#061; false) {<br \/>\n    pthread_mutex_unlock(&amp;mutex); \/\/ \u624b\u52a8\u89e3\u9501<br \/>\n    pthread_cond_wait(&amp;cond, NULL); \/\/ \u65e0\u4e92\u65a5\u91cf\u7684\u7b49\u5f85<br \/>\n    pthread_mutex_lock(&amp;mutex); \/\/ \u91cd\u65b0\u52a0\u9501<br \/>\n}<br \/>\npthread_mutex_unlock(&amp;mutex);<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fd9\u79cd\u5199\u6cd5\u5b58\u5728\u81f4\u547d\u95ee\u9898&#xff1a;\u89e3\u9501\u548c\u7b49\u5f85\u4e0d\u662f\u539f\u5b50\u64cd\u4f5c\u3002\u5728<span style=\"color:#956fe7\">pthread_mutex_unlock<\/span>\u548c<span style=\"color:#956fe7\">pthread_cond_wait<\/span>\u4e4b\u95f4&#xff0c;\u53ef\u80fd\u6709\u5176\u4ed6\u7ebf\u7a0b\u4fee\u6539\u4e86\u5171\u4eab\u8d44\u6e90&#xff0c;\u4f7f\u6761\u4ef6\u6ee1\u8db3\u5e76\u8c03\u7528\u4e86<span style=\"color:#956fe7\">pthread_cond_signal<\/span>&#xff1b;\u4f46\u6b64\u65f6\u5f53\u524d\u7ebf\u7a0b\u8fd8\u672a\u8fdb\u5165\u7b49\u5f85\u72b6\u6001&#xff0c;\u8fd9\u4e2a\u5524\u9192\u4fe1\u53f7\u4f1a\u88ab\u6c38\u4e45\u9519\u8fc7&#xff0c;\u5bfc\u81f4\u7ebf\u7a0b\u6c38\u8fdc\u963b\u585e\u5728<span style=\"color:#956fe7\">pthread_cond_wait<\/span>\u4e2d\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u800c<span style=\"color:#956fe7\">pthread_cond_wait<\/span>\u5c06 \u201c\u89e3\u9501\u201d \u548c \u201c\u7b49\u5f85\u201d \u5c01\u88c5\u6210\u539f\u5b50\u64cd\u4f5c&#xff0c;\u4ece\u6839\u672c\u4e0a\u907f\u514d\u4e86\u4fe1\u53f7\u4e22\u5931\u7684\u95ee\u9898\u3002<\/p>\n<h4 id=\"2.4.2%20%E6%A0%B8%E5%BF%83%E5%8E%9F%E5%9B%A0%202%EF%BC%9A%E4%BF%9D%E8%AF%81%E5%85%B1%E4%BA%AB%E8%B5%84%E6%BA%90%E7%9A%84%E8%AE%BF%E9%97%AE%E5%AE%89%E5%85%A8\">2.4.2 \u6838\u5fc3\u539f\u56e0 2&#xff1a;\u4fdd\u8bc1\u5171\u4eab\u8d44\u6e90\u7684\u8bbf\u95ee\u5b89\u5168<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6761\u4ef6\u53d8\u91cf\u7684\u7b49\u5f85\u6761\u4ef6&#xff08;\u5982\u961f\u5217\u662f\u5426\u4e3a\u7a7a\u3001\u662f\u5426\u6ee1&#xff09;\u662f\u57fa\u4e8e\u5171\u4eab\u8d44\u6e90\u7684&#xff0c;\u800c\u5171\u4eab\u8d44\u6e90\u7684\u8bbf\u95ee\u5fc5\u987b\u4fdd\u8bc1\u4e92\u65a5\u3002\u5982\u679c\u6ca1\u6709\u4e92\u65a5\u91cf&#xff0c;\u591a\u4e2a\u7ebf\u7a0b\u53ef\u80fd\u540c\u65f6\u68c0\u67e5\u548c\u4fee\u6539\u7b49\u5f85\u6761\u4ef6&#xff0c;\u5bfc\u81f4\u7ade\u6001\u6761\u4ef6\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6bd4\u5982&#xff1a;\u591a\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b\u540c\u65f6\u68c0\u67e5 \u201c\u961f\u5217\u662f\u5426\u4e3a\u7a7a\u201d&#xff0c;\u5982\u679c\u6ca1\u6709\u4e92\u65a5\u91cf&#xff0c;\u53ef\u80fd\u591a\u4e2a\u7ebf\u7a0b\u90fd\u5224\u65ad\u961f\u5217\u4e3a\u7a7a\u5e76\u8fdb\u5165\u7b49\u5f85&#xff1b;\u5f53\u751f\u4ea7\u8005\u751f\u4ea7\u4e00\u4e2a\u6570\u636e\u540e&#xff0c;\u8c03\u7528signal\u5524\u9192\u4e00\u4e2a\u7ebf\u7a0b&#xff0c;\u5176\u4ed6\u7ebf\u7a0b\u4ecd\u4f1a\u6c38\u8fdc\u7b49\u5f85&#xff0c;\u8fd9\u5c31\u662f\u5178\u578b\u7684\u540c\u6b65\u5b89\u5168\u95ee\u9898\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u603b\u7ed3&#xff1a;\u4e92\u65a5\u91cf\u4fdd\u8bc1\u4e86\u5171\u4eab\u8d44\u6e90&#xff08;\u7b49\u5f85\u6761\u4ef6&#xff09;\u7684\u8bbf\u95ee\u5b89\u5168&#xff0c;pthread_cond_wait\u7684\u539f\u5b50\u64cd\u4f5c\u907f\u514d\u4e86\u5524\u9192\u4fe1\u53f7\u7684\u4e22\u5931&#xff0c;\u4e8c\u8005\u7f3a\u4e00\u4e0d\u53ef\u3002<\/p>\n<h3 id=\"2.5%20%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E7%9A%84%E4%BD%BF%E7%94%A8%E8%A7%84%E8%8C%83%EF%BC%9A%E7%94%A8%20while%20%E5%88%A4%E6%96%AD%E6%9D%A1%E4%BB%B6%EF%BC%8C%E8%80%8C%E9%9D%9E%20if\">2.5 \u6761\u4ef6\u53d8\u91cf\u7684\u4f7f\u7528\u89c4\u8303&#xff1a;\u7528 while \u5224\u65ad\u6761\u4ef6&#xff0c;\u800c\u975e if<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728\u4f7f\u7528\u6761\u4ef6\u53d8\u91cf\u65f6&#xff0c;\u5fc5\u987b\u7528while\u5faa\u73af\u5224\u65ad\u7b49\u5f85\u6761\u4ef6&#xff0c;\u800c\u4e0d\u662fif\u5224\u65ad&#xff0c;\u8fd9\u662f\u907f\u514d \u201c\u4f2a\u5524\u9192\u201d \u7684\u5173\u952e&#xff0c;\u4e5f\u662f\u5f00\u53d1\u4e2d\u7684\u9ad8\u9891\u5751\u3002<\/p>\n<h4 id=\"2.5.1%20%E4%BB%80%E4%B9%88%E6%98%AF%E4%BC%AA%E5%94%A4%E9%86%92%EF%BC%9F\">2.5.1 \u4ec0\u4e48\u662f\u4f2a\u5524\u9192&#xff1f;<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4f2a\u5524\u9192&#xff1a;\u7ebf\u7a0b\u5728\u6ca1\u6709\u88ab\u5176\u4ed6\u7ebf\u7a0b\u8c03\u7528<span style=\"color:#956fe7\">signal<\/span>\u6216<span style=\"color:#956fe7\">broadcast<\/span>\u7684\u60c5\u51b5\u4e0b&#xff0c;\u4ece<span style=\"color:#fe2c24\"><span style=\"background-color:#fbd4d0\">pthread_cond_wait<\/span><\/span>\u4e2d\u88ab\u5524\u9192\u3002\u8fd9\u662f\u64cd\u4f5c\u7cfb\u7edf\u7684\u5e95\u5c42\u5b9e\u73b0\u5bfc\u81f4\u7684&#xff08;\u5982\u4fe1\u53f7\u4e2d\u65ad\u3001\u7ebf\u7a0b\u8c03\u5ea6\u4f18\u5316&#xff09;&#xff0c;\u662f\u6761\u4ef6\u53d8\u91cf\u7684\u56fa\u6709\u7279\u6027&#xff0c;\u65e0\u6cd5\u907f\u514d\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\u679c\u7528<span style=\"color:#956fe7\">if<\/span>\u5224\u65ad\u6761\u4ef6&#xff0c;\u4f2a\u5524\u9192\u4f1a\u5bfc\u81f4\u7ebf\u7a0b\u5728\u6761\u4ef6\u4e0d\u6ee1\u8db3\u65f6\u7ee7\u7eed\u6267\u884c&#xff0c;\u4ece\u800c\u5f15\u53d1\u7a0b\u5e8f\u5f02\u5e38&#xff1b;\u800c\u7528<span style=\"color:#956fe7\">while<\/span>\u5faa\u73af\u5224\u65ad&#xff0c;\u5373\u4f7f\u53d1\u751f\u4f2a\u5524\u9192&#xff0c;\u7ebf\u7a0b\u4f1a\u91cd\u65b0\u68c0\u67e5\u6761\u4ef6&#xff0c;\u82e5\u6761\u4ef6\u4e0d\u6ee1\u8db3\u5219\u518d\u6b21\u8fdb\u5165\u7b49\u5f85&#xff0c;\u4ece\u6839\u672c\u4e0a\u907f\u514d\u4e86\u4f2a\u5524\u9192\u7684\u5f71\u54cd\u3002<\/p>\n<h4 id=\"2.5.2%20%E6%AD%A3%E7%A1%AE%E7%9A%84%E4%BD%BF%E7%94%A8%E6%A8%A1%E6%9D%BF%EF%BC%88%E5%BF%85%E8%AE%B0%EF%BC%89\">2.5.2 \u6b63\u786e\u7684\u4f7f\u7528\u6a21\u677f&#xff08;\u5fc5\u8bb0&#xff09;<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6761\u4ef6\u53d8\u91cf\u7684\u4f7f\u7528\u6709\u4e25\u683c\u7684\u89c4\u8303&#xff0c;\u5206\u4e3a \u201c\u7b49\u5f85\u6761\u4ef6\u201d \u548c \u201c\u53d1\u9001\u4fe1\u53f7\u201d \u4e24\u90e8\u5206&#xff0c;\u8fd9\u662f\u901a\u7528\u7684\u5b89\u5168\u6a21\u677f&#xff0c;\u65e0\u8bba\u4ec0\u4e48\u573a\u666f\u90fd\u53ef\u4ee5\u76f4\u63a5\u5957\u7528&#xff1a;<\/p>\n<h5 id=\"%E6%A8%A1%E6%9D%BF%201%EF%BC%9A%E7%AD%89%E5%BE%85%E6%9D%A1%E4%BB%B6%E7%9A%84%E7%BA%BF%E7%A8%8B%EF%BC%88%E5%A6%82%E6%B6%88%E8%B4%B9%E8%80%85%EF%BC%89\">\u6a21\u677f 1&#xff1a;\u7b49\u5f85\u6761\u4ef6\u7684\u7ebf\u7a0b&#xff08;\u5982\u6d88\u8d39\u8005&#xff09;<\/h5>\n<p>\/\/ 1. \u52a0\u9501&#xff0c;\u4fdd\u8bc1\u5171\u4eab\u8d44\u6e90\u7684\u4e92\u65a5\u8bbf\u95ee<br \/>\npthread_mutex_lock(&amp;mutex);<\/p>\n<p>\/\/ 2. while\u5faa\u73af\u5224\u65ad\u6761\u4ef6&#xff0c;\u907f\u514d\u4f2a\u5524\u9192<br \/>\nwhile (\u6761\u4ef6\u4e0d\u6ee1\u8db3) { \/\/ \u5982&#xff1a;\u961f\u5217\u4e3a\u7a7a<br \/>\n    pthread_cond_wait(&amp;cond, &amp;mutex); \/\/ \u7b49\u5f85\u5e76\u81ea\u52a8\u89e3\u9501<br \/>\n}<\/p>\n<p>\/\/ 3. \u6761\u4ef6\u6ee1\u8db3&#xff0c;\u64cd\u4f5c\u4e34\u754c\u8d44\u6e90<br \/>\n\/\/ &#8230; \u4e1a\u52a1\u903b\u8f91&#xff08;\u5982\u4ece\u961f\u5217\u53d6\u6570\u636e&#xff09; &#8230;<\/p>\n<p>\/\/ 4. \u89e3\u9501&#xff0c;\u91ca\u653e\u4e34\u754c\u8d44\u6e90<br \/>\npthread_mutex_unlock(&amp;mutex);<\/p>\n<h5 id=\"%E6%A8%A1%E6%9D%BF%202%EF%BC%9A%E5%8F%91%E9%80%81%E4%BF%A1%E5%8F%B7%E7%9A%84%E7%BA%BF%E7%A8%8B%EF%BC%88%E5%A6%82%E7%94%9F%E4%BA%A7%E8%80%85%EF%BC%89\">\u6a21\u677f 2&#xff1a;\u53d1\u9001\u4fe1\u53f7\u7684\u7ebf\u7a0b&#xff08;\u5982\u751f\u4ea7\u8005&#xff09;<\/h5>\n<p>\/\/ 1. \u52a0\u9501&#xff0c;\u4fdd\u8bc1\u5171\u4eab\u8d44\u6e90\u7684\u4e92\u65a5\u8bbf\u95ee<br \/>\npthread_mutex_lock(&amp;mutex);<\/p>\n<p>\/\/ 2. \u4fee\u6539\u5171\u4eab\u8d44\u6e90&#xff0c;\u4f7f\u7b49\u5f85\u6761\u4ef6\u6ee1\u8db3<br \/>\n\/\/ &#8230; \u4e1a\u52a1\u903b\u8f91&#xff08;\u5982\u5411\u961f\u5217\u52a0\u6570\u636e&#xff09; &#8230;<\/p>\n<p>\/\/ 3. \u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b<br \/>\npthread_cond_signal(&amp;cond); \/\/ \u6216pthread_cond_broadcast<\/p>\n<p>\/\/ 4. \u89e3\u9501&#xff0c;\u8ba9\u88ab\u5524\u9192\u7684\u7ebf\u7a0b\u91cd\u65b0\u7ade\u4e89\u4e92\u65a5\u91cf<br \/>\npthread_mutex_unlock(&amp;mutex);<\/p>\n<p>\u6838\u5fc3\u8981\u70b9&#xff1a;<\/p>\n<li>\u7b49\u5f85\u6761\u4ef6\u5fc5\u987b\u7528<span style=\"color:#956fe7\">while<\/span>&#xff0c;\u7edd\u5bf9\u4e0d\u80fd\u7528<span style=\"color:#956fe7\">if<\/span>&#xff1b;<\/li>\n<li>\u65e0\u8bba\u662f\u7b49\u5f85\u8fd8\u662f\u53d1\u9001\u4fe1\u53f7&#xff0c;\u64cd\u4f5c\u5171\u4eab\u8d44\u6e90\u524d\u5fc5\u987b\u52a0\u9501&#xff0c;\u64cd\u4f5c\u5b8c\u6210\u540e\u5fc5\u987b\u89e3\u9501&#xff1b;<\/li>\n<li>\u5524\u9192\u64cd\u4f5c&#xff08;signal\/broadcast&#xff09;\u53ef\u4ee5\u5728\u52a0\u9501\u540e\u6216\u89e3\u9501\u524d\u6267\u884c&#xff0c;\u52a0\u9501\u540e\u6267\u884c\u66f4\u5b89\u5168&#xff08;\u907f\u514d\u4fe1\u53f7\u4e22\u5931&#xff09;\u3002<\/li>\n<h3 id=\"2.6%20%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E7%9A%84%20C%2B%2B%20%E5%B0%81%E8%A3%85%EF%BC%9ARAII%20%E9%A3%8E%E6%A0%BC%E6%9B%B4%E4%BC%98%E9%9B%85\">2.6 \u6761\u4ef6\u53d8\u91cf\u7684 C&#043;&#043; \u5c01\u88c5&#xff1a;RAII \u98ce\u683c\u66f4\u4f18\u96c5<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728 C \u8bed\u8a00\u4e2d&#xff0c;\u4f7f\u7528\u6761\u4ef6\u53d8\u91cf\u9700\u8981\u624b\u52a8\u8c03\u7528\u521d\u59cb\u5316\u3001\u9500\u6bc1\u3001\u7b49\u5f85\u3001\u5524\u9192\u51fd\u6570&#xff0c;\u5bb9\u6613\u51fa\u73b0\u9057\u6f0f&#xff1b;\u800c\u5728 C&#043;&#043; \u4e2d&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5229\u7528RAII&#xff08;\u8d44\u6e90\u83b7\u53d6\u5373\u521d\u59cb\u5316&#xff09; \u601d\u60f3\u5bf9\u6761\u4ef6\u53d8\u91cf\u8fdb\u884c\u5c01\u88c5&#xff0c;\u7ed3\u5408\u4e4b\u524d\u5c01\u88c5\u7684\u4e92\u65a5\u91cf&#xff0c;\u8ba9\u4ee3\u7801\u66f4\u5b89\u5168\u3001\u66f4\u4f18\u96c5&#xff0c;\u540c\u65f6\u4fdd\u8bc1\u53ef\u590d\u7528\u6027\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6211\u4eec\u5c06\u5c01\u88c5\u7684\u4ee3\u7801\u5199\u5728Cond.hpp\u5934\u6587\u4ef6\u4e2d&#xff0c;\u4f9d\u8d56\u4e4b\u524d\u5c01\u88c5\u7684Lock.hpp&#xff08;\u5305\u542bMutex\u548cLockGuard\u7c7b&#xff09;\u3002<\/p>\n<h4 id=\"2.6.1%20%E5%B0%81%E8%A3%85%E4%BB%A3%E7%A0%81%EF%BC%9ACond.hpp\">2.6.1 \u5c01\u88c5\u4ee3\u7801&#xff1a;Cond.hpp<\/h4>\n<p>#pragma once<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\n#include &lt;cassert&gt;<br \/>\n#include &#034;Lock.hpp&#034; \/\/ \u5f15\u5165\u4e4b\u524d\u5c01\u88c5\u7684\u4e92\u65a5\u91cf<\/p>\n<p>\/\/ \u547d\u540d\u7a7a\u95f4&#xff0c;\u907f\u514d\u547d\u540d\u51b2\u7a81<br \/>\nnamespace CondModule {<br \/>\n    using namespace LockModule; \/\/ \u590d\u7528\u4e92\u65a5\u91cf\u7684\u5c01\u88c5<\/p>\n<p>    class Cond {<br \/>\n    public:<br \/>\n        \/\/ \u7981\u6b62\u62f7\u8d1d\u548c\u8d4b\u503c&#xff08;\u6761\u4ef6\u53d8\u91cf\u4e0d\u80fd\u88ab\u62f7\u8d1d&#xff09;<br \/>\n        Cond(const Cond&amp;) &#061; delete;<br \/>\n        Cond&amp; operator&#061;(const Cond&amp;) &#061; delete;<\/p>\n<p>        \/\/ \u6784\u9020\u51fd\u6570&#xff1a;\u52a8\u6001\u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf<br \/>\n        Cond() {<br \/>\n            int ret &#061; pthread_cond_init(&amp;_cond, nullptr);<br \/>\n            assert(ret &#061;&#061; 0); \/\/ \u8c03\u8bd5\u9636\u6bb5\u65ad\u8a00&#xff0c;release\u7248\u672c\u81ea\u52a8\u5931\u6548<br \/>\n            (void)ret; \/\/ \u907f\u514d\u7f16\u8bd1\u8b66\u544a<br \/>\n        }<\/p>\n<p>        \/\/ \u7b49\u5f85\u6761\u4ef6\u53d8\u91cf&#xff1a;\u63a5\u6536\u81ea\u5b9a\u4e49\u7684Mutex\u5bf9\u8c61<br \/>\n        void Wait(Mutex&amp; mutex) {<br \/>\n            \/\/ \u83b7\u53d6\u539f\u751f\u7684pthread_mutex_t\u6307\u9488&#xff0c;\u4e0e\u5e95\u5c42\u63a5\u53e3\u517c\u5bb9<br \/>\n            int ret &#061; pthread_cond_wait(&amp;_cond, mutex.GetMutexOriginal());<br \/>\n            assert(ret &#061;&#061; 0);<br \/>\n            (void)ret;<br \/>\n        }<\/p>\n<p>        \/\/ \u5524\u9192\u4e00\u4e2a\u7b49\u5f85\u7684\u7ebf\u7a0b<br \/>\n        void Notify() {<br \/>\n            int ret &#061; pthread_cond_signal(&amp;_cond);<br \/>\n            assert(ret &#061;&#061; 0);<br \/>\n            (void)ret;<br \/>\n        }<\/p>\n<p>        \/\/ \u5524\u9192\u6240\u6709\u7b49\u5f85\u7684\u7ebf\u7a0b<br \/>\n        void NotifyAll() {<br \/>\n            int ret &#061; pthread_cond_broadcast(&amp;_cond);<br \/>\n            assert(ret &#061;&#061; 0);<br \/>\n            (void)ret;<br \/>\n        }<\/p>\n<p>        \/\/ \u6790\u6784\u51fd\u6570&#xff1a;\u9500\u6bc1\u6761\u4ef6\u53d8\u91cf<br \/>\n        ~Cond() {<br \/>\n            int ret &#061; pthread_cond_destroy(&amp;_cond);<br \/>\n            assert(ret &#061;&#061; 0);<br \/>\n            (void)ret;<br \/>\n        }<\/p>\n<p>    private:<br \/>\n        pthread_cond_t _cond; \/\/ \u539f\u751f\u7684\u6761\u4ef6\u53d8\u91cf\u5bf9\u8c61<br \/>\n    };<br \/>\n}<\/p>\n<h4 id=\"2.6.2%20%E5%B0%81%E8%A3%85%E4%BB%A3%E7%A0%81%E8%A7%A3%E6%9E%90\">2.6.2 \u5c01\u88c5\u4ee3\u7801\u89e3\u6790<\/h4>\n<li>\u7981\u6b62\u62f7\u8d1d\u548c\u8d4b\u503c&#xff1a;\u6761\u4ef6\u53d8\u91cf\u662f\u72ec\u5360\u8d44\u6e90&#xff0c;\u901a\u8fc7<span style=\"color:#fe2c24\"><span style=\"background-color:#fbd4d0\">&#061; delete<\/span><\/span>\u7981\u7528\u62f7\u8d1d\u6784\u9020\u548c\u8d4b\u503c\u8fd0\u7b97\u7b26&#xff0c;\u907f\u514d\u8bef\u7528&#xff1b;<\/li>\n<li>\u4e0e\u81ea\u5b9a\u4e49 Mutex \u7c7b\u914d\u5408&#xff1a;Wait\u65b9\u6cd5\u63a5\u6536\u81ea\u5b9a\u4e49\u7684Mutex\u5bf9\u8c61&#xff0c;\u901a\u8fc7<span style=\"color:#956fe7\">GetMutexOriginal<\/span>\u83b7\u53d6\u539f\u751f\u4e92\u65a5\u91cf\u6307\u9488&#xff0c;\u4fdd\u8bc1\u5c01\u88c5\u7684\u4e00\u81f4\u6027\u548c\u517c\u5bb9\u6027&#xff1b;<\/li>\n<li>RAII \u98ce\u683c&#xff1a;\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf&#xff0c;\u6790\u6784\u51fd\u6570\u9500\u6bc1&#xff0c;\u65e0\u9700\u624b\u52a8\u7ba1\u7406\u8d44\u6e90&#xff0c;\u907f\u514d\u9057\u6f0f&#xff1b;<\/li>\n<li>\u7b80\u6d01\u63a5\u53e3&#xff1a;\u5bf9\u5916\u66b4\u9732Wait\u3001Notify\u3001NotifyAll\u4e09\u4e2a\u6838\u5fc3\u63a5\u53e3&#xff0c;\u9690\u85cf\u5e95\u5c42\u7684 pthread \u5e93\u5b9e\u73b0&#xff0c;\u964d\u4f4e\u4f7f\u7528\u6210\u672c\u3002<\/li>\n<h4 id=\"2.6.3%20%E5%B0%81%E8%A3%85%E5%90%8E%E7%9A%84%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B\">2.6.3 \u5c01\u88c5\u540e\u7684\u4f7f\u7528\u793a\u4f8b<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7ed3\u5408Lock.hpp\u548cCond.hpp&#xff0c;\u91cd\u5199\u4e4b\u524d\u7684\u7b49\u5f85 &#8211; \u5524\u9192\u6848\u4f8b&#xff0c;\u4ee3\u7801\u66f4\u7b80\u6d01\u5b89\u5168&#xff1a;<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &#034;Lock.hpp&#034;<br \/>\n#include &#034;Cond.hpp&#034;<\/p>\n<p>using namespace LockModule;<br \/>\nusing namespace CondModule;<\/p>\n<p>\/\/ \u81ea\u5b9a\u4e49\u7684\u4e92\u65a5\u91cf\u548c\u6761\u4ef6\u53d8\u91cf<br \/>\nMutex mutex;<br \/>\nCond cond;<\/p>\n<p>void *wait_thread(void *arg) {<br \/>\n    char *thread_name &#061; static_cast&lt;char*&gt;(arg);<br \/>\n    while (true) {<br \/>\n        LockGuard lock(mutex); \/\/ RAII\u52a0\u9501&#xff0c;\u81ea\u52a8\u89e3\u9501<br \/>\n        std::cout &lt;&lt; thread_name &lt;&lt; &#034;&#xff1a;\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u8fdb\u5165\u7b49\u5f85&#8230;&#034; &lt;&lt; std::endl;<br \/>\n        cond.Wait(mutex); \/\/ \u7b49\u5f85\u6761\u4ef6\u53d8\u91cf<br \/>\n        std::cout &lt;&lt; thread_name &lt;&lt; &#034;&#xff1a;\u88ab\u5524\u9192&#xff0c;\u6267\u884c\u4efb\u52a1&#8230;&#034; &lt;&lt; std::endl;<br \/>\n        sleep(1);<br \/>\n    }<br \/>\n    return nullptr;<br \/>\n}<\/p>\n<p>int main(void) {<br \/>\n    pthread_t t1, t2;<br \/>\n    pthread_create(&amp;t1, NULL, wait_thread, (void*)&#034;\u7ebf\u7a0bA&#034;);<br \/>\n    pthread_create(&amp;t2, NULL, wait_thread, (void*)&#034;\u7ebf\u7a0bB&#034;);<\/p>\n<p>    sleep(2);<br \/>\n    int count &#061; 0;<br \/>\n    while (count &lt; 3) {<br \/>\n        std::cout &lt;&lt; &#034;\\\\n\u4e3b\u7ebf\u7a0b&#xff1a;\u51c6\u5907\u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b&#xff08;\u7b2c&#034; &lt;&lt; count&#043;1 &lt;&lt; &#034;\u6b21&#xff09;&#034; &lt;&lt; std::endl;<br \/>\n        cond.NotifyAll(); \/\/ \u5524\u9192\u6240\u6709\u7ebf\u7a0b<br \/>\n        sleep(2);<br \/>\n        count&#043;&#043;;<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u53ef\u4ee5\u770b\u5230&#xff0c;\u5c01\u88c5\u540e\u7684\u4ee3\u7801\u65e0\u9700\u624b\u52a8\u52a0\u9501 \/ \u89e3\u9501\u3001\u521d\u59cb\u5316 \/ \u9500\u6bc1\u8d44\u6e90&#xff0c;\u6781\u5927\u5730\u964d\u4f4e\u4e86\u51fa\u9519\u6982\u7387&#xff0c;\u8fd9\u4e5f\u662f C&#043;&#043; \u5c01\u88c5\u7684\u6838\u5fc3\u4f18\u52bf\u3002<\/p>\n<\/p>\n<h2 id=\"%E4%B8%89%E3%80%81%E7%94%9F%E4%BA%A7%E8%80%85%E6%B6%88%E8%B4%B9%E8%80%85%E6%A8%A1%E5%9E%8B%EF%BC%9A%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%E7%9A%84%E7%BB%8F%E5%85%B8%E5%AE%9E%E6%88%98\" style=\"background-color:transparent\">\u4e09\u3001\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b&#xff1a;\u7ebf\u7a0b\u540c\u6b65\u7684\u7ecf\u5178\u5b9e\u6218<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u662f\u7ebf\u7a0b\u540c\u6b65\u7684\u7ecf\u5178\u5e94\u7528\u573a\u666f&#xff0c;\u51e0\u4e4e\u6240\u6709\u591a\u7ebf\u7a0b\u534f\u4f5c\u6846\u67b6&#xff08;\u5982\u7ebf\u7a0b\u6c60\u3001\u6d88\u606f\u961f\u5217&#xff09;\u90fd\u57fa\u4e8e\u8fd9\u4e2a\u6a21\u578b\u5b9e\u73b0\u3002\u5b83\u901a\u8fc7\u4e00\u4e2a\u7f13\u51b2\u533a&#xff08;\u5982\u961f\u5217&#xff09; \u5c06\u751f\u4ea7\u8005\u7ebf\u7a0b\u548c\u6d88\u8d39\u8005\u7ebf\u7a0b\u89e3\u8026&#xff0c;\u8ba9\u4e8c\u8005\u5404\u53f8\u5176\u804c\u3001\u6709\u5e8f\u534f\u4f5c&#xff0c;\u662f\u89e3\u51b3\u591a\u7ebf\u7a0b\u534f\u4f5c\u95ee\u9898\u7684 \u201c\u4e07\u80fd\u6a21\u677f\u201d\u3002<\/p>\n<h3 id=\"3.1%20%E7%94%9F%E4%BA%A7%E8%80%85%E6%B6%88%E8%B4%B9%E8%80%85%E6%A8%A1%E5%9E%8B%E7%9A%84%20%E2%80%9C321%E2%80%9D%20%E5%8E%9F%E5%88%99%EF%BC%88%E5%BF%85%E8%AE%B0%EF%BC%89\">3.1 \u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u7684 \u201c321\u201d \u539f\u5219&#xff08;\u5fc5\u8bb0&#xff09;<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e3a\u4e86\u65b9\u4fbf\u8bb0\u5fc6\u548c\u7406\u89e3&#xff0c;\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u53ef\u4ee5\u603b\u7ed3\u4e3a \u201c321\u201d \u539f\u5219&#xff0c;\u8fd9\u662f\u6a21\u578b\u7684\u6838\u5fc3\u7cbe\u9ad3&#xff1a;<\/p>\n<ul>\n<li>3 \u79cd\u5173\u7cfb&#xff1a;\u751f\u4ea7\u8005\u4e0e\u751f\u4ea7\u8005&#xff08;\u4e92\u65a5&#xff09;\u3001\u6d88\u8d39\u8005\u4e0e\u6d88\u8d39\u8005&#xff08;\u4e92\u65a5&#xff09;\u3001\u751f\u4ea7\u8005\u4e0e\u6d88\u8d39\u8005&#xff08;\u4e92\u65a5 &#043; \u540c\u6b65&#xff09;&#xff1b;<\/li>\n<li>2 \u7c7b\u89d2\u8272&#xff1a;\u751f\u4ea7\u8005\u7ebf\u7a0b&#xff08;\u751f\u4ea7\u6570\u636e&#xff0c;\u653e\u5165\u7f13\u51b2\u533a&#xff09;\u3001\u6d88\u8d39\u8005\u7ebf\u7a0b&#xff08;\u4ece\u7f13\u51b2\u533a\u53d6\u6570\u636e&#xff0c;\u6d88\u8d39\u6570\u636e&#xff09;&#xff1b;<\/li>\n<li>1 \u4e2a\u7f13\u51b2\u533a&#xff1a;\u4f5c\u4e3a\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u7684\u4e2d\u95f4\u4ecb\u8d28&#xff0c;\u89e3\u8026\u4e8c\u8005&#xff0c;\u5e73\u8861\u751f\u4ea7\u548c\u6d88\u8d39\u7684\u901f\u5ea6\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"456\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260302144214-69a5a1c66962a.png\" width=\"1024\" \/><\/p>\n<h4 id=\"3%20%E7%A7%8D%E5%85%B3%E7%B3%BB%E8%AF%A6%E8%A7%A3%EF%BC%9A\">3 \u79cd\u5173\u7cfb\u8be6\u89e3&#xff1a;<\/h4>\n<li>\u751f\u4ea7\u8005\u4e0e\u751f\u4ea7\u8005\u4e92\u65a5&#xff1a;\u591a\u4e2a\u751f\u4ea7\u8005\u4e0d\u80fd\u540c\u65f6\u5411\u7f13\u51b2\u533a\u5199\u5165\u6570\u636e&#xff08;\u907f\u514d\u6570\u636e\u8986\u76d6&#xff09;&#xff1b;<\/li>\n<li>\u6d88\u8d39\u8005\u4e0e\u6d88\u8d39\u8005\u4e92\u65a5&#xff1a;\u591a\u4e2a\u6d88\u8d39\u8005\u4e0d\u80fd\u540c\u65f6\u4ece\u7f13\u51b2\u533a\u8bfb\u53d6\u6570\u636e&#xff08;\u907f\u514d\u91cd\u590d\u6d88\u8d39&#xff09;&#xff1b;<\/li>\n<li>\u751f\u4ea7\u8005\u4e0e\u6d88\u8d39\u8005\u4e92\u65a5 &#043; \u540c\u6b65&#xff1a;\n<ul>\n<li>\u4e92\u65a5&#xff1a;\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u4e0d\u80fd\u540c\u65f6\u64cd\u4f5c\u7f13\u51b2\u533a&#xff08;\u4fdd\u8bc1\u6570\u636e\u5b89\u5168&#xff09;&#xff1b;<\/li>\n<li>\u540c\u6b65&#xff1a;\u751f\u4ea7\u8005\u751f\u4ea7\u6570\u636e\u540e&#xff0c;\u9700\u8981\u901a\u77e5\u6d88\u8d39\u8005&#xff1b;\u6d88\u8d39\u8005\u6d88\u8d39\u6570\u636e\u540e&#xff0c;\u9700\u8981\u901a\u77e5\u751f\u4ea7\u8005\u3002<\/li>\n<\/ul>\n<\/li>\n<h3 id=\"3.2%20%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E7%94%9F%E4%BA%A7%E8%80%85%E6%B6%88%E8%B4%B9%E8%80%85%E6%A8%A1%E5%9E%8B%EF%BC%9F\">3.2 \u4e3a\u4ec0\u4e48\u9700\u8981\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b&#xff1f;<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728\u6ca1\u6709\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u7684\u60c5\u51b5\u4e0b&#xff0c;\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u76f4\u63a5\u4ea4\u4e92&#xff0c;\u4f1a\u5b58\u5728\u4ee5\u4e0b\u95ee\u9898&#xff1a;<\/p>\n<li>\u5f3a\u8026\u5408&#xff1a;\u751f\u4ea7\u8005\u5fc5\u987b\u77e5\u9053\u6d88\u8d39\u8005\u7684\u5b58\u5728&#xff0c;\u6d88\u8d39\u8005\u4e5f\u5fc5\u987b\u77e5\u9053\u751f\u4ea7\u8005\u7684\u5b58\u5728&#xff0c;\u4e00\u65b9\u7684\u4fee\u6539\u4f1a\u76f4\u63a5\u5f71\u54cd\u53e6\u4e00\u65b9&#xff1b;<\/li>\n<li>\u901f\u5ea6\u4e0d\u5339\u914d&#xff1a;\u751f\u4ea7\u8005\u751f\u4ea7\u901f\u5ea6\u5feb&#xff0c;\u6d88\u8d39\u8005\u6d88\u8d39\u901f\u5ea6\u6162&#xff0c;\u4f1a\u5bfc\u81f4\u751f\u4ea7\u8005\u963b\u585e&#xff1b;\u53cd\u4e4b&#xff0c;\u6d88\u8d39\u8005\u4f1a\u9891\u7e41\u8f6e\u8be2&#xff0c;\u6d6a\u8d39 CPU \u8d44\u6e90&#xff1b;<\/li>\n<li>\u5e76\u53d1\u6548\u7387\u4f4e&#xff1a;\u76f4\u63a5\u4ea4\u4e92\u4f1a\u5bfc\u81f4\u4e34\u754c\u8d44\u6e90\u7684\u7ade\u4e89\u8fc7\u4e8e\u6fc0\u70c8&#xff0c;\u964d\u4f4e\u7a0b\u5e8f\u7684\u5e76\u53d1\u6548\u7387\u3002<\/li>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u800c\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u901a\u8fc7\u7f13\u51b2\u533a\u89e3\u51b3\u4e86\u8fd9\u4e9b\u95ee\u9898&#xff1a;<\/p>\n<li>\u89e3\u8026&#xff1a;\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u65e0\u9700\u77e5\u9053\u5f7c\u6b64\u7684\u5b58\u5728&#xff0c;\u53ea\u9700\u8981\u64cd\u4f5c\u7f13\u51b2\u533a&#xff0c;\u964d\u4f4e\u4e86\u4ee3\u7801\u7684\u8026\u5408\u5ea6&#xff1b;<\/li>\n<li>\u5e73\u8861\u901f\u5ea6&#xff1a;\u7f13\u51b2\u533a\u76f8\u5f53\u4e8e \u201c\u84c4\u6c34\u6c60\u201d&#xff0c;\u751f\u4ea7\u8005\u751f\u4ea7\u7684\u6570\u636e\u53ef\u4ee5\u5148\u5b58\u5165\u7f13\u51b2\u533a&#xff0c;\u6d88\u8d39\u8005\u6309\u9700\u4ece\u7f13\u51b2\u533a\u53d6\u6570\u636e&#xff0c;\u5e73\u8861\u4e86\u4e8c\u8005\u7684\u901f\u5ea6&#xff1b;<\/li>\n<li>\u63d0\u9ad8\u5e76\u53d1&#xff1a;\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u53ef\u4ee5\u72ec\u7acb\u6267\u884c&#xff0c;\u53ea\u6709\u64cd\u4f5c\u7f13\u51b2\u533a\u65f6\u624d\u4f1a\u7ade\u4e89\u4e34\u754c\u8d44\u6e90&#xff0c;\u63d0\u9ad8\u4e86\u7a0b\u5e8f\u7684\u5e76\u53d1\u6548\u7387\u3002<\/li>\n<h3 id=\"3.3%20%E5%9F%BA%E4%BA%8E%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E7%9A%84%E7%94%9F%E4%BA%A7%E8%80%85%E6%B6%88%E8%B4%B9%E8%80%85%E6%A8%A1%E5%9E%8B%EF%BC%88%E6%9D%A1%E4%BB%B6%E5%8F%98%E9%87%8F%E5%AE%9E%E7%8E%B0%EF%BC%89\">3.3 \u57fa\u4e8e\u963b\u585e\u961f\u5217\u7684\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b&#xff08;\u6761\u4ef6\u53d8\u91cf\u5b9e\u73b0&#xff09;<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u963b\u585e\u961f\u5217&#xff08;BlockingQueue&#xff09; \u662f\u5b9e\u73b0\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u7684\u6700\u4f73\u8f7d\u4f53&#xff0c;\u5b83\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u961f\u5217&#xff0c;\u5177\u6709\u4ee5\u4e0b\u7279\u6027&#xff1a;<\/p>\n<ul>\n<li>\u5f53\u961f\u5217\u4e3a\u7a7a\u65f6&#xff0c;\u6d88\u8d39\u8005\u4ece\u961f\u5217\u53d6\u6570\u636e\u7684\u64cd\u4f5c\u4f1a\u963b\u585e&#xff0c;\u76f4\u5230\u961f\u5217\u4e2d\u6709\u6570\u636e&#xff1b;<\/li>\n<li>\u5f53\u961f\u5217\u4e3a\u6ee1\u65f6&#xff0c;\u751f\u4ea7\u8005\u5411\u961f\u5217\u5b58\u6570\u636e\u7684\u64cd\u4f5c\u4f1a\u963b\u585e&#xff0c;\u76f4\u5230\u961f\u5217\u4e2d\u6709\u7a7a\u95f2\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"200\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260302144214-69a5a1c68ba28.png\" width=\"490\" \/><\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u963b\u585e\u961f\u5217\u7684\u963b\u585e\u7279\u6027\u6b63\u597d\u5951\u5408\u4e86\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u7684\u540c\u6b65\u9700\u6c42&#xff0c;\u6211\u4eec\u4f7f\u7528 \u201c\u6761\u4ef6\u53d8\u91cf &#043; \u4e92\u65a5\u91cf\u201d \u5b9e\u73b0\u963b\u585e\u961f\u5217&#xff0c;\u5e76\u57fa\u4e8e\u6b64\u5b9e\u73b0\u591a\u751f\u4ea7\u8005\u591a\u6d88\u8d39\u8005\u6a21\u578b\u3002<\/p>\n<h4 id=\"3.3.1%20%E5%AE%9E%E7%8E%B0%E6%80%9D%E8%B7%AF\">3.3.1 \u5b9e\u73b0\u601d\u8def<\/h4>\n<li>\u7f13\u51b2\u533a&#xff1a;\u4f7f\u7528 C&#043;&#043; \u7684<span style=\"color:#956fe7\">std::queue<\/span>\u4f5c\u4e3a\u5e95\u5c42\u7f13\u51b2\u533a&#xff0c;\u6307\u5b9a\u961f\u5217\u7684\u6700\u5927\u5bb9\u91cf&#xff08;\u4e0a\u9650&#xff09;&#xff1b;<\/li>\n<li>\u4e92\u65a5\u91cf&#xff1a;\u4fdd\u62a4\u961f\u5217\u7684\u64cd\u4f5c&#xff08;\u5165\u961f \/ \u51fa\u961f \/ \u5224\u7a7a \/ \u5224\u6ee1&#xff09;&#xff0c;\u4fdd\u8bc1\u540c\u4e00\u65f6\u523b\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u64cd\u4f5c\u961f\u5217&#xff1b;<\/li>\n<li>\u6761\u4ef6\u53d8\u91cf&#xff1a;\u4f7f\u7528\u4e24\u4e2a\u6761\u4ef6\u53d8\u91cf&#xff0c;\u5206\u522b\u5b9e\u73b0\u751f\u4ea7\u8005\u7b49\u5f85\u548c\u6d88\u8d39\u8005\u7b49\u5f85&#xff1a;\n<ul>\n<li><span style=\"color:#956fe7\">_prod_cond<\/span>&#xff1a;\u751f\u4ea7\u8005\u6761\u4ef6\u53d8\u91cf&#xff0c;\u961f\u5217\u4e3a\u6ee1\u65f6&#xff0c;\u751f\u4ea7\u8005\u963b\u585e\u7b49\u5f85&#xff1b;<\/li>\n<li><span style=\"color:#956fe7\">_cons_cond<\/span>&#xff1a;\u6d88\u8d39\u8005\u6761\u4ef6\u53d8\u91cf&#xff0c;\u961f\u5217\u4e3a\u7a7a\u65f6&#xff0c;\u6d88\u8d39\u8005\u963b\u585e\u7b49\u5f85&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>\u7b49\u5f85\u8ba1\u6570&#xff1a;\u8bb0\u5f55\u7b49\u5f85\u7684\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u6570\u91cf&#xff0c;\u907f\u514d\u65e0\u610f\u4e49\u7684\u5524\u9192&#xff0c;\u63d0\u9ad8\u6548\u7387&#xff1b;<\/li>\n<li>\u6838\u5fc3\u63a5\u53e3&#xff1a;\n<ul>\n<li><span style=\"color:#956fe7\">Enqueue<\/span>&#xff1a;\u751f\u4ea7\u8005\u63a5\u53e3&#xff0c;\u5411\u961f\u5217\u4e2d\u6dfb\u52a0\u6570\u636e&#xff0c;\u961f\u6ee1\u65f6\u963b\u585e&#xff1b;<\/li>\n<li><span style=\"color:#956fe7\">Dequeue<\/span>&#xff1a;\u6d88\u8d39\u8005\u63a5\u53e3&#xff0c;\u4ece\u961f\u5217\u4e2d\u53d6\u51fa\u6570\u636e&#xff0c;\u961f\u7a7a\u65f6\u963b\u585e\u3002<\/li>\n<\/ul>\n<\/li>\n<h4 id=\"3.3.2%20%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E5%AE%9E%E7%8E%B0%EF%BC%9ABlockQueue.hpp%EF%BC%88%E6%A8%A1%E6%9D%BF%E7%B1%BB%EF%BC%89\">3.3.2 \u963b\u585e\u961f\u5217\u5b9e\u73b0&#xff1a;BlockQueue.hpp&#xff08;\u6a21\u677f\u7c7b&#xff09;<\/h4>\n<p>#ifndef __BLOCK_QUEUE_HPP__<br \/>\n#define __BLOCK_QUEUE_HPP__<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;queue&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\n#include &lt;cassert&gt;<br \/>\n#include &lt;unistd.h&gt;<\/p>\n<p>\/\/ \u6a21\u677f\u7c7b&#xff0c;\u652f\u6301\u4efb\u610f\u7c7b\u578b\u7684\u5143\u7d20&#xff08;\u5982int\u3001\u81ea\u5b9a\u4e49\u4efb\u52a1\u5bf9\u8c61&#xff09;<br \/>\ntemplate &lt;typename T&gt;<br \/>\nclass BlockQueue {<br \/>\nprivate:<br \/>\n    \/\/ \u5224\u6ee1&#xff1a;\u961f\u5217\u5927\u5c0f\u7b49\u4e8e\u6700\u5927\u5bb9\u91cf<br \/>\n    bool IsFull() const {<br \/>\n        return _queue.size() &#061;&#061; _capacity;<br \/>\n    }<\/p>\n<p>    \/\/ \u5224\u7a7a&#xff1a;\u961f\u5217\u4e3a\u7a7a<br \/>\n    bool IsEmpty() const {<br \/>\n        return _queue.empty();<br \/>\n    }<\/p>\n<p>public:<br \/>\n    \/\/ \u6784\u9020\u51fd\u6570&#xff1a;\u521d\u59cb\u5316\u961f\u5217\u5bb9\u91cf\u548c\u540c\u6b65\u8d44\u6e90<br \/>\n    BlockQueue(int capacity)<br \/>\n        : _capacity(capacity), _prod_wait_cnt(0), _cons_wait_cnt(0) {<br \/>\n        \/\/ \u521d\u59cb\u5316\u4e92\u65a5\u91cf\u548c\u6761\u4ef6\u53d8\u91cf<br \/>\n        int ret &#061; pthread_mutex_init(&amp;_mutex, nullptr);<br \/>\n        assert(ret &#061;&#061; 0);<br \/>\n        ret &#061; pthread_cond_init(&amp;_prod_cond, nullptr);<br \/>\n        assert(ret &#061;&#061; 0);<br \/>\n        ret &#061; pthread_cond_init(&amp;_cons_cond, nullptr);<br \/>\n        assert(ret &#061;&#061; 0);<br \/>\n        (void)ret; \/\/ \u907f\u514d\u7f16\u8bd1\u8b66\u544a<br \/>\n    }<\/p>\n<p>    \/\/ \u6790\u6784\u51fd\u6570&#xff1a;\u9500\u6bc1\u540c\u6b65\u8d44\u6e90<br \/>\n    ~BlockQueue() {<br \/>\n        pthread_mutex_destroy(&amp;_mutex);<br \/>\n        pthread_cond_destroy(&amp;_prod_cond);<br \/>\n        pthread_cond_destroy(&amp;_cons_cond);<br \/>\n    }<\/p>\n<p>    \/\/ \u751f\u4ea7\u8005\u63a5\u53e3&#xff1a;\u5165\u961f&#xff0c;\u961f\u6ee1\u65f6\u963b\u585e<br \/>\n    void Enqueue(const T&amp; data) {<br \/>\n        \/\/ 1. \u52a0\u9501&#xff0c;\u4fdd\u8bc1\u961f\u5217\u64cd\u4f5c\u7684\u4e92\u65a5\u6027<br \/>\n        pthread_mutex_lock(&amp;_mutex);<\/p>\n<p>        \/\/ 2. while\u5faa\u73af\u5224\u6ee1&#xff0c;\u907f\u514d\u4f2a\u5524\u9192<br \/>\n        while (IsFull()) {<br \/>\n            _prod_wait_cnt&#043;&#043;;<br \/>\n            std::cout &lt;&lt; &#034;\u961f\u5217\u6ee1&#xff08;\u5bb9\u91cf&#xff1a;&#034; &lt;&lt; _capacity &lt;&lt; &#034;&#xff09;&#xff0c;\u751f\u4ea7\u8005[&#034; &lt;&lt; pthread_self() &lt;&lt; &#034;]\u8fdb\u5165\u7b49\u5f85&#8230;&#034; &lt;&lt; std::endl;<br \/>\n            pthread_cond_wait(&amp;_prod_cond, &amp;_mutex); \/\/ \u7b49\u5f85\u5e76\u81ea\u52a8\u89e3\u9501<br \/>\n            _prod_wait_cnt&#8211;;<br \/>\n        }<\/p>\n<p>        \/\/ 3. \u961f\u672a\u6ee1&#xff0c;\u751f\u4ea7\u6570\u636e&#xff08;\u5165\u961f&#xff09;<br \/>\n        _queue.push(data);<br \/>\n        std::cout &lt;&lt; &#034;\u751f\u4ea7\u8005[&#034; &lt;&lt; pthread_self() &lt;&lt; &#034;]\u751f\u4ea7\u6570\u636e&#xff1a;&#034; &lt;&lt; data<br \/>\n                  &lt;&lt; &#034;&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;&#034; &lt;&lt; _queue.size() &lt;&lt; std::endl;<\/p>\n<p>        \/\/ 4. \u5524\u9192\u7b49\u5f85\u7684\u6d88\u8d39\u8005&#xff08;\u5982\u679c\u6709&#xff09;<br \/>\n        if (_cons_wait_cnt &gt; 0) {<br \/>\n            std::cout &lt;&lt; &#034;\u5524\u9192\u4e00\u4e2a\u7b49\u5f85\u7684\u6d88\u8d39\u8005&#034; &lt;&lt; std::endl;<br \/>\n            pthread_cond_signal(&amp;_cons_cond);<br \/>\n        }<\/p>\n<p>        \/\/ 5. \u89e3\u9501<br \/>\n        pthread_mutex_unlock(&amp;_mutex);<br \/>\n    }<\/p>\n<p>    \/\/ \u6d88\u8d39\u8005\u63a5\u53e3&#xff1a;\u51fa\u961f&#xff0c;\u961f\u7a7a\u65f6\u963b\u585e<br \/>\n    void Dequeue(T&amp; data) {<br \/>\n        \/\/ 1. \u52a0\u9501&#xff0c;\u4fdd\u8bc1\u961f\u5217\u64cd\u4f5c\u7684\u4e92\u65a5\u6027<br \/>\n        pthread_mutex_lock(&amp;_mutex);<\/p>\n<p>        \/\/ 2. while\u5faa\u73af\u5224\u7a7a&#xff0c;\u907f\u514d\u4f2a\u5524\u9192<br \/>\n        while (IsEmpty()) {<br \/>\n            _cons_wait_cnt&#043;&#043;;<br \/>\n            std::cout &lt;&lt; &#034;\u961f\u5217\u4e3a\u7a7a&#xff0c;\u6d88\u8d39\u8005[&#034; &lt;&lt; pthread_self() &lt;&lt; &#034;]\u8fdb\u5165\u7b49\u5f85&#8230;&#034; &lt;&lt; std::endl;<br \/>\n            pthread_cond_wait(&amp;_cons_cond, &amp;_mutex); \/\/ \u7b49\u5f85\u5e76\u81ea\u52a8\u89e3\u9501<br \/>\n            _cons_wait_cnt&#8211;;<br \/>\n        }<\/p>\n<p>        \/\/ 3. \u961f\u975e\u7a7a&#xff0c;\u6d88\u8d39\u6570\u636e&#xff08;\u51fa\u961f&#xff09;<br \/>\n        data &#061; _queue.front();<br \/>\n        _queue.pop();<br \/>\n        std::cout &lt;&lt; &#034;\u6d88\u8d39\u8005[&#034; &lt;&lt; pthread_self() &lt;&lt; &#034;]\u6d88\u8d39\u6570\u636e&#xff1a;&#034; &lt;&lt; data<br \/>\n                  &lt;&lt; &#034;&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;&#034; &lt;&lt; _queue.size() &lt;&lt; std::endl;<\/p>\n<p>        \/\/ 4. \u5524\u9192\u7b49\u5f85\u7684\u751f\u4ea7\u8005&#xff08;\u5982\u679c\u6709&#xff09;<br \/>\n        if (_prod_wait_cnt &gt; 0) {<br \/>\n            std::cout &lt;&lt; &#034;\u5524\u9192\u4e00\u4e2a\u7b49\u5f85\u7684\u751f\u4ea7\u8005&#034; &lt;&lt; std::endl;<br \/>\n            pthread_cond_signal(&amp;_prod_cond);<br \/>\n        }<\/p>\n<p>        \/\/ 5. \u89e3\u9501<br \/>\n        pthread_mutex_unlock(&amp;_mutex);<br \/>\n    }<\/p>\n<p>private:<br \/>\n    std::queue&lt;T&gt; _queue;          \/\/ \u5e95\u5c42\u7f13\u51b2\u533a&#xff1a;\u961f\u5217<br \/>\n    int _capacity;                 \/\/ \u961f\u5217\u6700\u5927\u5bb9\u91cf<br \/>\n    pthread_mutex_t _mutex;        \/\/ \u4fdd\u62a4\u961f\u5217\u7684\u4e92\u65a5\u91cf<br \/>\n    pthread_cond_t _prod_cond;     \/\/ \u751f\u4ea7\u8005\u6761\u4ef6\u53d8\u91cf<br \/>\n    pthread_cond_t _cons_cond;     \/\/ \u6d88\u8d39\u8005\u6761\u4ef6\u53d8\u91cf<br \/>\n    int _prod_wait_cnt;            \/\/ \u7b49\u5f85\u7684\u751f\u4ea7\u8005\u6570\u91cf<br \/>\n    int _cons_wait_cnt;            \/\/ \u7b49\u5f85\u7684\u6d88\u8d39\u8005\u6570\u91cf<br \/>\n};<\/p>\n<p>#endif \/\/ __BLOCK_QUEUE_HPP__<\/p>\n<h4 id=\"3.3.3%20%E7%94%9F%E4%BA%A7%E8%80%85%E6%B6%88%E8%B4%B9%E8%80%85%E6%A8%A1%E5%9E%8B%E6%B5%8B%E8%AF%95%E4%BB%A3%E7%A0%81%EF%BC%9Amain.cpp\" style=\"background-color:transparent\">3.3.3 \u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u6d4b\u8bd5\u4ee3\u7801&#xff1a;main.cpp<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6211\u4eec\u521b\u5efa 2 \u4e2a\u751f\u4ea7\u8005\u7ebf\u7a0b\u548c 3 \u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b&#xff0c;\u6d4b\u8bd5\u963b\u585e\u961f\u5217\u7684\u529f\u80fd&#xff0c;\u751f\u4ea7\u8005\u6bcf\u9694 1 \u79d2\u751f\u4ea7\u4e00\u4e2a\u6574\u6570&#xff0c;\u6d88\u8d39\u8005\u6bcf\u9694 2 \u79d2\u6d88\u8d39\u4e00\u4e2a\u6574\u6570&#xff1a;<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &#034;BlockQueue.hpp&#034;<\/p>\n<p>\/\/ \u963b\u585e\u961f\u5217&#xff1a;\u5bb9\u91cf\u4e3a5&#xff0c;\u5b58\u50a8int\u7c7b\u578b\u6570\u636e<br \/>\nBlockQueue&lt;int&gt; g_block_queue(5);<\/p>\n<p>\/\/ \u751f\u4ea7\u8005\u7ebf\u7a0b\u6267\u884c\u51fd\u6570<br \/>\nvoid *producer_thread(void *arg) {<br \/>\n    int producer_id &#061; *(static_cast&lt;int*&gt;(arg));<br \/>\n    delete static_cast&lt;int*&gt;(arg); \/\/ \u91ca\u653e\u52a8\u6001\u5206\u914d\u7684\u53c2\u6570<\/p>\n<p>    int data &#061; 0;<br \/>\n    while (true) {<br \/>\n        \/\/ \u751f\u4ea7\u6570\u636e&#xff1a;\u7b80\u5355\u9012\u589e\u7684\u6574\u6570<br \/>\n        data&#043;&#043;;<br \/>\n        g_block_queue.Enqueue(data);<\/p>\n<p>        \/\/ \u6a21\u62df\u751f\u4ea7\u8017\u65f6<br \/>\n        sleep(1);<br \/>\n    }<br \/>\n    return nullptr;<br \/>\n}<\/p>\n<p>\/\/ \u6d88\u8d39\u8005\u7ebf\u7a0b\u6267\u884c\u51fd\u6570<br \/>\nvoid *consumer_thread(void *arg) {<br \/>\n    int consumer_id &#061; *(static_cast&lt;int*&gt;(arg));<br \/>\n    delete static_cast&lt;int*&gt;(arg); \/\/ \u91ca\u653e\u52a8\u6001\u5206\u914d\u7684\u53c2\u6570<\/p>\n<p>    while (true) {<br \/>\n        int data &#061; 0;<br \/>\n        g_block_queue.Dequeue(data);<\/p>\n<p>        \/\/ \u6a21\u62df\u6d88\u8d39\u8017\u65f6<br \/>\n        sleep(2);<br \/>\n    }<br \/>\n    return nullptr;<br \/>\n}<\/p>\n<p>int main(void) {<br \/>\n    std::cout &lt;&lt; &#034;\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u542f\u52a8&#xff08;2\u751f\u4ea7\u8005&#xff0c;3\u6d88\u8d39\u8005&#xff0c;\u961f\u5217\u5bb9\u91cf5&#xff09;&#034; &lt;&lt; std::endl;<\/p>\n<p>    \/\/ \u521b\u5efa2\u4e2a\u751f\u4ea7\u8005\u7ebf\u7a0b<br \/>\n    pthread_t prod_tids[2];<br \/>\n    for (int i &#061; 0; i &lt; 2; &#043;&#043;i) {<br \/>\n        int *id &#061; new int(i&#043;1);<br \/>\n        pthread_create(&amp;prod_tids[i], NULL, producer_thread, static_cast&lt;void*&gt;(id));<br \/>\n    }<\/p>\n<p>    \/\/ \u521b\u5efa3\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b<br \/>\n    pthread_t cons_tids[3];<br \/>\n    for (int i &#061; 0; i &lt; 3; &#043;&#043;i) {<br \/>\n        int *id &#061; new int(i&#043;1);<br \/>\n        pthread_create(&amp;cons_tids[i], NULL, consumer_thread, static_cast&lt;void*&gt;(id));<br \/>\n    }<\/p>\n<p>    \/\/ \u7b49\u5f85\u7ebf\u7a0b\u6267\u884c&#xff08;\u5b9e\u9645\u4e0d\u4f1a\u9000\u51fa&#xff0c;\u8fd9\u91cc\u4ec5\u4f5c\u6f14\u793a&#xff09;<br \/>\n    for (int i &#061; 0; i &lt; 2; &#043;&#043;i) {<br \/>\n        pthread_join(prod_tids[i], NULL);<br \/>\n    }<br \/>\n    for (int i &#061; 0; i &lt; 3; &#043;&#043;i) {<br \/>\n        pthread_join(cons_tids[i], NULL);<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<h4 id=\"3.3.4%20%E7%BC%96%E8%AF%91%E8%BF%90%E8%A1%8C%E4%B8%8E%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90\">3.3.4 \u7f16\u8bd1\u8fd0\u884c\u4e0e\u7ed3\u679c\u5206\u6790<\/h4>\n<p># \u7f16\u8bd1&#xff1a;\u94fe\u63a5pthread\u5e93<br \/>\ng&#043;&#043; main.cpp -o prod_cons -lpthread<br \/>\n# \u8fd0\u884c<br \/>\n.\/prod_cons<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff08;\u5173\u952e\u90e8\u5206&#xff09;&#xff1a;<\/p>\n<p>\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u542f\u52a8&#xff08;2\u751f\u4ea7\u8005&#xff0c;3\u6d88\u8d39\u8005&#xff0c;\u961f\u5217\u5bb9\u91cf5&#xff09;<br \/>\n\u751f\u4ea7\u8005[140709348478720]\u751f\u4ea7\u6570\u636e&#xff1a;1&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;1<br \/>\n\u5524\u9192\u4e00\u4e2a\u7b49\u5f85\u7684\u6d88\u8d39\u8005<br \/>\n\u6d88\u8d39\u8005[140709331693312]\u6d88\u8d39\u6570\u636e&#xff1a;1&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;0<br \/>\n\u5524\u9192\u4e00\u4e2a\u7b49\u5f85\u7684\u751f\u4ea7\u8005<br \/>\n\u751f\u4ea7\u8005[140709340086016]\u751f\u4ea7\u6570\u636e&#xff1a;1&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;1<br \/>\n\u5524\u9192\u4e00\u4e2a\u7b49\u5f85\u7684\u6d88\u8d39\u8005<br \/>\n\u751f\u4ea7\u8005[140709348478720]\u751f\u4ea7\u6570\u636e&#xff1a;2&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;2<br \/>\n\u751f\u4ea7\u8005[140709340086016]\u751f\u4ea7\u6570\u636e&#xff1a;2&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;3<br \/>\n\u751f\u4ea7\u8005[140709348478720]\u751f\u4ea7\u6570\u636e&#xff1a;3&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;4<br \/>\n\u751f\u4ea7\u8005[140709340086016]\u751f\u4ea7\u6570\u636e&#xff1a;3&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;5<br \/>\n\u751f\u4ea7\u8005[140709348478720]\u751f\u4ea7\u6570\u636e&#xff1a;4&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;5<br \/>\n\u961f\u5217\u6ee1&#xff08;\u5bb9\u91cf&#xff1a;5&#xff09;&#xff0c;\u751f\u4ea7\u8005[140709348478720]\u8fdb\u5165\u7b49\u5f85&#8230;<br \/>\n\u6d88\u8d39\u8005[140709323300608]\u6d88\u8d39\u6570\u636e&#xff1a;2&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;4<br \/>\n\u5524\u9192\u4e00\u4e2a\u7b49\u5f85\u7684\u751f\u4ea7\u8005<br \/>\n\u751f\u4ea7\u8005[140709348478720]\u751f\u4ea7\u6570\u636e&#xff1a;4&#xff0c;\u961f\u5217\u5f53\u524d\u5927\u5c0f&#xff1a;5<br \/>\n\u961f\u5217\u6ee1&#xff08;\u5bb9\u91cf&#xff1a;5&#xff09;&#xff0c;\u751f\u4ea7\u8005[140709348478720]\u8fdb\u5165\u7b49\u5f85&#8230;<\/p>\n<p>\u7ed3\u679c\u5206\u6790&#xff1a;<\/p>\n<li>\u961f\u5217\u5bb9\u91cf\u4e3a 5&#xff0c;\u5f53\u751f\u4ea7\u8005\u751f\u4ea7\u901f\u5ea6\u5927\u4e8e\u6d88\u8d39\u8005\u6d88\u8d39\u901f\u5ea6\u65f6&#xff0c;\u961f\u5217\u6ee1\u540e\u751f\u4ea7\u8005\u8fdb\u5165\u7b49\u5f85&#xff1b;<\/li>\n<li>\u6d88\u8d39\u8005\u6d88\u8d39\u6570\u636e\u540e&#xff0c;\u4f1a\u5524\u9192\u7b49\u5f85\u7684\u751f\u4ea7\u8005&#xff0c;\u8ba9\u5176\u7ee7\u7eed\u751f\u4ea7&#xff1b;<\/li>\n<li>\u961f\u5217\u4e3a\u7a7a\u65f6&#xff0c;\u6d88\u8d39\u8005\u8fdb\u5165\u7b49\u5f85&#xff0c;\u751f\u4ea7\u8005\u751f\u4ea7\u6570\u636e\u540e\u4f1a\u5524\u9192\u6d88\u8d39\u8005&#xff1b;<\/li>\n<li>\u6240\u6709\u7ebf\u7a0b\u6709\u5e8f\u534f\u4f5c&#xff0c;\u6ca1\u6709\u51fa\u73b0\u6570\u636e\u8986\u76d6\u3001\u91cd\u590d\u6d88\u8d39\u6216\u961f\u5217\u6ea2\u51fa\u7684\u95ee\u9898&#xff0c;\u5145\u5206\u4f53\u73b0\u4e86\u7ebf\u7a0b\u540c\u6b65\u7684\u6838\u5fc3\u4ef7\u503c\u3002<\/li>\n<h3 id=\"3.4%20%E6%A8%A1%E5%9E%8B%E6%89%A9%E5%B1%95%EF%BC%9A%E6%94%AF%E6%8C%81%E8%87%AA%E5%AE%9A%E4%B9%89%E4%BB%BB%E5%8A%A1%E7%B1%BB%E5%9E%8B\" style=\"background-color:transparent\">3.4 \u6a21\u578b\u6269\u5c55&#xff1a;\u652f\u6301\u81ea\u5b9a\u4e49\u4efb\u52a1\u7c7b\u578b<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u963b\u585e\u961f\u5217\u7684\u6a21\u677f\u8bbe\u8ba1\u652f\u6301\u4efb\u610f\u7c7b\u578b\u7684\u6570\u636e&#xff0c;\u9664\u4e86\u6574\u6570&#xff0c;\u6211\u4eec\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u81ea\u5b9a\u4e49\u4efb\u52a1\u7c7b\u578b&#xff08;\u5982\u8ba1\u7b97\u4efb\u52a1\u3001IO \u4efb\u52a1&#xff09;&#xff0c;\u8ba9\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u66f4\u8d34\u8fd1\u5b9e\u9645\u5f00\u53d1\u573a\u666f\u3002<\/p>\n<h4 id=\"3.4.1%20%E8%87%AA%E5%AE%9A%E4%B9%89%E4%BB%BB%E5%8A%A1%E7%B1%BB%E5%9E%8B%EF%BC%9ATask.hpp\">3.4.1 \u81ea\u5b9a\u4e49\u4efb\u52a1\u7c7b\u578b&#xff1a;Task.hpp<\/h4>\n<p>#pragma once<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &lt;functional&gt;<\/p>\n<p>\/\/ \u4efb\u52a1\u7c7b\u578b&#xff1a;\u652f\u6301\u4efb\u610f\u65e0\u53c2\u65e0\u8fd4\u56de\u503c\u7684\u51fd\u6570<br \/>\nusing Task &#061; std::function&lt;void()&gt;;<\/p>\n<p>\/\/ \u793a\u4f8b\u4efb\u52a1&#xff1a;\u52a0\u6cd5\u8ba1\u7b97<br \/>\nvoid AddTask(int a, int b) {<br \/>\n    int result &#061; a &#043; b;<br \/>\n    std::cout &lt;&lt; &#034;\u4efb\u52a1\u6267\u884c&#xff1a;&#034; &lt;&lt; a &lt;&lt; &#034; &#043; &#034; &lt;&lt; b &lt;&lt; &#034; &#061; &#034; &lt;&lt; result &lt;&lt; std::endl;<br \/>\n}<\/p>\n<p>\/\/ \u793a\u4f8b\u4efb\u52a1&#xff1a;\u5b57\u7b26\u4e32\u6253\u5370<br \/>\nvoid PrintTask(const std::string&amp; msg) {<br \/>\n    std::cout &lt;&lt; &#034;\u4efb\u52a1\u6267\u884c&#xff1a;&#034; &lt;&lt; msg &lt;&lt; std::endl;<br \/>\n}<\/p>\n<h4 id=\"3.4.2%20%E6%B5%8B%E8%AF%95%E4%BB%A3%E7%A0%81%EF%BC%9Amain_task.cpp\">3.4.2 \u6d4b\u8bd5\u4ee3\u7801&#xff1a;main_task.cpp<\/h4>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &#034;BlockQueue.hpp&#034;<br \/>\n#include &#034;Task.hpp&#034;<\/p>\n<p>\/\/ \u963b\u585e\u961f\u5217&#xff1a;\u5b58\u50a8Task\u7c7b\u578b<br \/>\nBlockQueue&lt;Task&gt; g_task_queue(3);<\/p>\n<p>\/\/ \u751f\u4ea7\u8005\u7ebf\u7a0b&#xff1a;\u751f\u4ea7\u4efb\u52a1<br \/>\nvoid *task_producer(void *arg) {<br \/>\n    int producer_id &#061; *(static_cast&lt;int*&gt;(arg));<br \/>\n    delete static_cast&lt;int*&gt;(arg);<\/p>\n<p>    int count &#061; 0;<br \/>\n    while (true) {<br \/>\n        \/\/ \u751f\u4ea7\u4e0d\u540c\u7684\u4efb\u52a1<br \/>\n        if (count % 2 &#061;&#061; 0) {<br \/>\n            \/\/ \u52a0\u6cd5\u4efb\u52a1<br \/>\n            Task task &#061; std::bind(AddTask, count, count&#043;1);<br \/>\n            g_task_queue.Enqueue(task);<br \/>\n            std::cout &lt;&lt; &#034;\u751f\u4ea7\u8005[&#034; &lt;&lt; producer_id &lt;&lt; &#034;]\u751f\u4ea7\u52a0\u6cd5\u4efb\u52a1&#xff1a;&#034; &lt;&lt; count &lt;&lt; &#034; &#043; &#034; &lt;&lt; count&#043;1 &lt;&lt; std::endl;<br \/>\n        } else {<br \/>\n            \/\/ \u6253\u5370\u4efb\u52a1<br \/>\n            std::string msg &#061; &#034;Hello, Producer &#034; &#043; std::to_string(producer_id) &#043; &#034;, Task &#034; &#043; std::to_string(count);<br \/>\n            Task task &#061; std::bind(PrintTask, msg);<br \/>\n            g_task_queue.Enqueue(task);<br \/>\n            std::cout &lt;&lt; &#034;\u751f\u4ea7\u8005[&#034; &lt;&lt; producer_id &lt;&lt; &#034;]\u751f\u4ea7\u6253\u5370\u4efb\u52a1&#xff1a;&#034; &lt;&lt; msg &lt;&lt; std::endl;<br \/>\n        }<\/p>\n<p>        count&#043;&#043;;<br \/>\n        sleep(1);<br \/>\n    }<br \/>\n    return nullptr;<br \/>\n}<\/p>\n<p>\/\/ \u6d88\u8d39\u8005\u7ebf\u7a0b&#xff1a;\u6d88\u8d39\u4efb\u52a1<br \/>\nvoid *task_consumer(void *arg) {<br \/>\n    int consumer_id &#061; *(static_cast&lt;int*&gt;(arg));<br \/>\n    delete static_cast&lt;int*&gt;(arg);<\/p>\n<p>    while (true) {<br \/>\n        Task task;<br \/>\n        g_task_queue.Dequeue(task);<\/p>\n<p>        \/\/ \u6267\u884c\u4efb\u52a1<br \/>\n        std::cout &lt;&lt; &#034;\u6d88\u8d39\u8005[&#034; &lt;&lt; consumer_id &lt;&lt; &#034;]\u5f00\u59cb\u6267\u884c\u4efb\u52a1&#034; &lt;&lt; std::endl;<br \/>\n        task();<\/p>\n<p>        sleep(2);<br \/>\n    }<br \/>\n    return nullptr;<br \/>\n}<\/p>\n<p>int main(void) {<br \/>\n    std::cout &lt;&lt; &#034;\u4efb\u52a1\u578b\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u542f\u52a8&#xff08;2\u751f\u4ea7\u8005&#xff0c;2\u6d88\u8d39\u8005&#xff0c;\u961f\u5217\u5bb9\u91cf3&#xff09;&#034; &lt;&lt; std::endl;<\/p>\n<p>    \/\/ \u521b\u5efa2\u4e2a\u751f\u4ea7\u8005\u7ebf\u7a0b<br \/>\n    pthread_t prod_tids[2];<br \/>\n    for (int i &#061; 0; i &lt; 2; &#043;&#043;i) {<br \/>\n        int *id &#061; new int(i&#043;1);<br \/>\n        pthread_create(&amp;prod_tids[i], NULL, task_producer, static_cast&lt;void*&gt;(id));<br \/>\n    }<\/p>\n<p>    \/\/ \u521b\u5efa2\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b<br \/>\n    pthread_t cons_tids[2];<br \/>\n    for (int i &#061; 0; i &lt; 2; &#043;&#043;i) {<br \/>\n        int *id &#061; new int(i&#043;1);<br \/>\n        pthread_create(&amp;cons_tids[i], NULL, task_consumer, static_cast&lt;void*&gt;(id));<br \/>\n    }<\/p>\n<p>    \/\/ \u7b49\u5f85\u7ebf\u7a0b\u6267\u884c<br \/>\n    for (int i &#061; 0; i &lt; 2; &#043;&#043;i) {<br \/>\n        pthread_join(prod_tids[i], NULL);<br \/>\n        pthread_join(cons_tids[i], NULL);<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<h4 id=\"3.4.3%20%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C\">3.4.3 \u8fd0\u884c\u7ed3\u679c<\/h4>\n<p>\u4efb\u52a1\u578b\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u542f\u52a8&#xff08;2\u751f\u4ea7\u8005&#xff0c;2\u6d88\u8d39\u8005&#xff0c;\u961f\u5217\u5bb9\u91cf3&#xff09;<br \/>\n\u751f\u4ea7\u8005[1]\u751f\u4ea7\u52a0\u6cd5\u4efb\u52a1&#xff1a;0 &#043; 1<br \/>\n\u5524\u9192\u4e00\u4e2a\u7b49\u5f85\u7684\u6d88\u8d39\u8005<br \/>\n\u6d88\u8d39\u8005[1]\u5f00\u59cb\u6267\u884c\u4efb\u52a1<br \/>\n\u4efb\u52a1\u6267\u884c&#xff1a;0 &#043; 1 &#061; 1<br \/>\n\u751f\u4ea7\u8005[2]\u751f\u4ea7\u6253\u5370\u4efb\u52a1&#xff1a;Hello, Producer 2, Task 0<br \/>\n\u751f\u4ea7\u8005[1]\u751f\u4ea7\u6253\u5370\u4efb\u52a1&#xff1a;Hello, Producer 1, Task 1<br \/>\n\u751f\u4ea7\u8005[2]\u751f\u4ea7\u52a0\u6cd5\u4efb\u52a1&#xff1a;1 &#043; 2<br \/>\n\u751f\u4ea7\u8005[1]\u751f\u4ea7\u52a0\u6cd5\u4efb\u52a1&#xff1a;2 &#043; 3<br \/>\n\u961f\u5217\u6ee1&#xff08;\u5bb9\u91cf&#xff1a;3&#xff09;&#xff0c;\u751f\u4ea7\u8005[1]\u8fdb\u5165\u7b49\u5f85&#8230;<br \/>\n\u6d88\u8d39\u8005[2]\u5f00\u59cb\u6267\u884c\u4efb\u52a1<br \/>\n\u4efb\u52a1\u6267\u884c&#xff1a;Hello, Producer 2, Task 0<br \/>\n\u5524\u9192\u4e00\u4e2a\u7b49\u5f85\u7684\u751f\u4ea7\u8005<br \/>\n\u751f\u4ea7\u8005[1]\u751f\u4ea7\u6253\u5370\u4efb\u52a1&#xff1a;Hello, Producer 1, Task 3<br \/>\n\u961f\u5217\u6ee1&#xff08;\u5bb9\u91cf&#xff1a;3&#xff09;&#xff0c;\u751f\u4ea7\u8005[1]\u8fdb\u5165\u7b49\u5f85&#8230;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fd9\u4e2a\u6269\u5c55\u6848\u4f8b\u5c55\u793a\u4e86\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u7684\u7075\u6d3b\u6027&#xff0c;\u901a\u8fc7\u81ea\u5b9a\u4e49\u4efb\u52a1\u7c7b\u578b&#xff0c;\u53ef\u4ee5\u5c06\u5176\u5e94\u7528\u4e8e\u5404\u79cd\u5b9e\u9645\u573a\u666f&#xff08;\u5982 Web \u670d\u52a1\u5668\u7684\u8bf7\u6c42\u5904\u7406\u3001\u540e\u53f0\u4efb\u52a1\u8c03\u5ea6\u7b49&#xff09;\u3002<\/p>\n<\/p>\n<h2 id=\"%E5%9B%9B%E3%80%81%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E4%B8%8E%E9%81%BF%E5%9D%91%E6%8C%87%E5%8D%97\">\u56db\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u907f\u5751\u6307\u5357<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728\u4f7f\u7528\u6761\u4ef6\u53d8\u91cf\u548c\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u65f6&#xff0c;\u5bb9\u6613\u9047\u5230\u4e00\u4e9b\u95ee\u9898&#xff0c;\u8fd9\u91cc\u603b\u7ed3\u4e86\u9ad8\u9891\u5751\u548c\u907f\u5751\u6280\u5de7&#xff0c;\u5e2e\u52a9\u4f60\u5199\u51fa\u66f4\u5065\u58ee\u7684\u4ee3\u7801\u3002<\/p>\n<h3 id=\"4.1%20%E5%9D%91%201%EF%BC%9A%E7%94%A8%20if%20%E5%88%A4%E6%96%AD%E6%9D%A1%E4%BB%B6%EF%BC%8C%E8%80%8C%E9%9D%9E%20while\">4.1 \u5751 1&#xff1a;\u7528 if \u5224\u65ad\u6761\u4ef6&#xff0c;\u800c\u975e while<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u95ee\u9898&#xff1a;\u4f7f\u7528<span style=\"color:#956fe7\">if<\/span>\u5224\u65ad\u7b49\u5f85\u6761\u4ef6&#xff0c;\u9047\u5230\u4f2a\u5524\u9192\u65f6&#xff0c;\u7ebf\u7a0b\u4f1a\u5728\u6761\u4ef6\u4e0d\u6ee1\u8db3\u7684\u60c5\u51b5\u4e0b\u7ee7\u7eed\u6267\u884c&#xff0c;\u5bfc\u81f4\u6570\u636e\u9519\u8bef&#xff1b;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u89e3\u51b3&#xff1a;\u5fc5\u987b\u7528<span style=\"color:#956fe7\">while<\/span>\u5faa\u73af\u5224\u65ad\u6761\u4ef6&#xff0c;\u5373\u4f7f\u88ab\u4f2a\u5524\u9192&#xff0c;\u4e5f\u4f1a\u91cd\u65b0\u68c0\u67e5\u6761\u4ef6&#xff0c;\u4e0d\u6ee1\u8db3\u5219\u7ee7\u7eed\u7b49\u5f85\u3002<\/p>\n<h3 id=\"4.2%20%E5%9D%91%202%EF%BC%9A%E5%BF%98%E8%AE%B0%E8%A7%A3%E9%94%81%E6%88%96%E8%A7%A3%E9%94%81%E6%97%B6%E6%9C%BA%E9%94%99%E8%AF%AF\">4.2 \u5751 2&#xff1a;\u5fd8\u8bb0\u89e3\u9501\u6216\u89e3\u9501\u65f6\u673a\u9519\u8bef<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u95ee\u9898&#xff1a;\u52a0\u9501\u540e\u5fd8\u8bb0\u89e3\u9501&#xff0c;\u6216\u5728\u6761\u4ef6\u5224\u65ad\u524d\u89e3\u9501&#xff0c;\u5bfc\u81f4\u6b7b\u9501\u6216\u6570\u636e\u7ade\u4e89&#xff1b;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u89e3\u51b3&#xff1a;<\/p>\n<li>\u4e25\u683c\u9075\u5faa \u201c\u52a0\u9501\u2192\u64cd\u4f5c\u2192\u89e3\u9501\u201d \u7684\u987a\u5e8f&#xff1b;<\/li>\n<li>\u5728 C&#043;&#043; \u4e2d\u4f7f\u7528 RAII \u98ce\u683c\u7684\u9501&#xff08;\u5982LockGuard&#xff09;&#xff0c;\u81ea\u52a8\u7ba1\u7406\u9501\u7684\u751f\u547d\u5468\u671f&#xff1b;<\/li>\n<li>\u6761\u4ef6\u53d8\u91cf\u7684wait\u51fd\u6570\u4f1a\u81ea\u52a8\u89e3\u9501&#xff0c;\u5524\u9192\u540e\u91cd\u65b0\u52a0\u9501&#xff0c;\u65e0\u9700\u624b\u52a8\u5e72\u9884\u3002<\/li>\n<h3 id=\"4.3%20%E5%9D%91%203%EF%BC%9A%E5%94%A4%E9%86%92%E5%87%BD%E6%95%B0%E4%BD%BF%E7%94%A8%E4%B8%8D%E5%BD%93\">4.3 \u5751 3&#xff1a;\u5524\u9192\u51fd\u6570\u4f7f\u7528\u4e0d\u5f53<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u95ee\u9898&#xff1a;\u5728\u591a\u751f\u4ea7\u8005\u591a\u6d88\u8d39\u8005\u573a\u666f\u4e2d&#xff0c;\u4f7f\u7528signal\u5524\u9192\u4e00\u4e2a\u7ebf\u7a0b&#xff0c;\u5bfc\u81f4\u90e8\u5206\u7ebf\u7a0b\u6c38\u8fdc\u7b49\u5f85&#xff1b;\u89e3\u51b3&#xff1a;<\/p>\n<li>\u591a\u751f\u4ea7\u8005\u591a\u6d88\u8d39\u8005\u573a\u666f\u4f7f\u7528<span style=\"color:#956fe7\">pthread_cond_broadcast<\/span>&#xff0c;\u5524\u9192\u6240\u6709\u7b49\u5f85\u7684\u7ebf\u7a0b&#xff1b;<\/li>\n<li>\u5355\u751f\u4ea7\u8005\u5355\u6d88\u8d39\u8005\u573a\u666f\u4f7f\u7528<span style=\"color:#956fe7\">pthread_cond_signal<\/span>&#xff0c;\u63d0\u9ad8\u6548\u7387\u3002<\/li>\n<h3 id=\"4.4%20%E5%9D%91%204%EF%BC%9A%E9%98%9F%E5%88%97%E5%AE%B9%E9%87%8F%E8%AE%BE%E8%AE%A1%E4%B8%8D%E5%90%88%E7%90%86\">4.4 \u5751 4&#xff1a;\u961f\u5217\u5bb9\u91cf\u8bbe\u8ba1\u4e0d\u5408\u7406<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u95ee\u9898&#xff1a;\u961f\u5217\u5bb9\u91cf\u8fc7\u5927\u5bfc\u81f4\u5185\u5b58\u6d6a\u8d39&#xff0c;\u8fc7\u5c0f\u5bfc\u81f4\u751f\u4ea7\u8005\u9891\u7e41\u7b49\u5f85&#xff1b;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u89e3\u51b3&#xff1a;\u6839\u636e\u5b9e\u9645\u573a\u666f\u8c03\u6574\u961f\u5217\u5bb9\u91cf&#xff0c;\u4e00\u822c\u8bbe\u7f6e\u4e3a CPU \u6838\u5fc3\u6570\u7684 2~4 \u500d&#xff0c;\u6216\u6839\u636e\u751f\u4ea7\u6d88\u8d39\u901f\u5ea6\u52a8\u6001\u8c03\u6574\u3002<\/p>\n<h3 id=\"4.5%20%E5%9D%91%205%EF%BC%9A%E7%BA%BF%E7%A8%8B%E9%80%80%E5%87%BA%E6%9C%BA%E5%88%B6%E7%BC%BA%E5%A4%B1\">4.5 \u5751 5&#xff1a;\u7ebf\u7a0b\u9000\u51fa\u673a\u5236\u7f3a\u5931<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u95ee\u9898&#xff1a;\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u7ebf\u7a0b\u8fdb\u5165\u65e0\u9650\u5faa\u73af&#xff0c;\u65e0\u6cd5\u6b63\u5e38\u9000\u51fa&#xff1b;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u89e3\u51b3&#xff1a;<\/p>\n<li>\u8bbe\u8ba1\u9000\u51fa\u6807\u5fd7&#xff08;\u5982\u5168\u5c40\u53d8\u91cfis_running&#xff09;&#xff0c;\u7ebf\u7a0b\u5b9a\u671f\u68c0\u67e5&#xff0c;\u6536\u5230\u9000\u51fa\u4fe1\u53f7\u540e\u9000\u51fa&#xff1b;<\/li>\n<li>\u4f7f\u7528\u4fe1\u53f7\u91cf\u6216\u6761\u4ef6\u53d8\u91cf\u901a\u77e5\u6240\u6709\u7ebf\u7a0b\u9000\u51fa&#xff0c;\u907f\u514d\u7ebf\u7a0b\u6cc4\u6f0f\u3002<\/li>\n<hr \/>\n<h2 id=\"%E6%80%BB%E7%BB%93\">\u603b\u7ed3<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u672c\u6587\u4f5c\u4e3a\u7ebf\u7a0b\u540c\u6b65\u7684\u4e0a\u7bc7&#xff0c;\u4ece\u6838\u5fc3\u6982\u5ff5\u51fa\u53d1&#xff0c;\u6df1\u5165\u8bb2\u89e3\u4e86\u6761\u4ef6\u53d8\u91cf\u7684\u539f\u7406\u4e0e\u7528\u6cd5&#xff0c;\u518d\u901a\u8fc7\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u5b8c\u6210\u4e86\u5b9e\u6218\u843d\u5730\u3002\u5728\u4e0b\u4e00\u7bc7\u6587\u7ae0\u4e2d&#xff0c;\u6211\u4eec\u5c06\u7ee7\u7eed\u6df1\u5165\u7ebf\u7a0b\u540c\u6b65\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\u679c\u672c\u6587\u5bf9\u4f60\u6709\u5e2e\u52a9&#xff0c;\u6b22\u8fce\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u5173\u6ce8&#xff01;\u5982\u679c\u5728\u5b66\u4e60\u8fc7\u7a0b\u4e2d\u9047\u5230\u4e86\u95ee\u9898&#xff0c;\u6216\u8005\u6709\u66f4\u597d\u7684\u5b9e\u6218\u6848\u4f8b&#xff0c;\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u7559\u8a00\u4ea4\u6d41&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u5728\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u4e16\u754c\u91cc&#xff0c;\u7ebf\u7a0b\u4e92\u65a5\u89e3\u51b3\u4e86 \u201c\u591a\u4e2a\u7ebf\u7a0b\u62a2\u8d44\u6e90\u201d \u7684\u95ee\u9898&#xff0c;\u4fdd\u8bc1\u4e86\u4e34\u754c\u8d44\u6e90\u7684\u72ec\u5360\u8bbf\u95ee&#xff1b;\u4f46\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u6211\u4eec\u8fd8\u9700\u8981\u89e3\u51b3 \u201c\u7ebf\u7a0b\u95f4\u6709\u5e8f\u534f\u4f5c\u201d \u7684\u95ee\u9898 \u2014\u2014 \u6bd4\u5982\u751f\u4ea7\u8005\u5fc5\u987b\u5148\u751f\u4ea7&#xff0c;\u6d88\u8d39\u8005\u624d\u80fd\u6d88\u8d39&#xff1b;\u961f\u5217\u4e3a\u7a7a\u65f6\u6d88\u8d39\u8005\u4e0d\u80fd\u778e\u5fd9\u6d3b&#xff0c;\u961f\u5217\u4e3a\u6ee1\u65f6\u751f\u4ea7\u8005\u4e0d\u80fd\u786c\u585e\u6570\u636e\u3002\u8fd9\u79cd \u201c\u5728\u4fdd\u8bc1\u6570\u636e\u5b89\u5168\u7684\u524d\u63d0\u4e0b&#xff0c;\u8ba9\u7ebf\u7a0b\u6309\u9884\u5b9a\u987a\u5e8f\u6267\u884c\u201d \u7684\u673a\u5236&#xff0c;\u5c31\u662f\u7ebf\u7a0b\u540c\u6b65\u3002 \u5982\u679c\u8bf4\u7ebf\u7a0b\u4e92\u65a5\u662f<\/p>\n","protected":false},"author":2,"featured_media":79723,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[8912,1054,58,16,3278,44,1714],"topic":[],"class_list":["post-79726","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-8912","tag-c-c","tag-linux","tag-16","tag-3278","tag-44","tag-1714"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Linux\u7cfb\u7edf\u7f16\u7a0b\u3011\uff08\u56db\u5341\u4e09\uff09\u7ebf\u7a0b\u540c\u6b65\u4e0a\u7bc7\uff1a\u4ece\u6761\u4ef6\u53d8\u91cf\u5230\u751f\u4ea7\u6d88\u8d39\u6a21\u578b\uff0c\u5403\u900f\u591a\u7ebf\u7a0b\u534f\u4f5c\u7cbe\u9ad3 - \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\/79726.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Linux\u7cfb\u7edf\u7f16\u7a0b\u3011\uff08\u56db\u5341\u4e09\uff09\u7ebf\u7a0b\u540c\u6b65\u4e0a\u7bc7\uff1a\u4ece\u6761\u4ef6\u53d8\u91cf\u5230\u751f\u4ea7\u6d88\u8d39\u6a21\u578b\uff0c\u5403\u900f\u591a\u7ebf\u7a0b\u534f\u4f5c\u7cbe\u9ad3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u524d\u8a00 \u5728\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u4e16\u754c\u91cc&#xff0c;\u7ebf\u7a0b\u4e92\u65a5\u89e3\u51b3\u4e86 \u201c\u591a\u4e2a\u7ebf\u7a0b\u62a2\u8d44\u6e90\u201d \u7684\u95ee\u9898&#xff0c;\u4fdd\u8bc1\u4e86\u4e34\u754c\u8d44\u6e90\u7684\u72ec\u5360\u8bbf\u95ee&#xff1b;\u4f46\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u6211\u4eec\u8fd8\u9700\u8981\u89e3\u51b3 \u201c\u7ebf\u7a0b\u95f4\u6709\u5e8f\u534f\u4f5c\u201d \u7684\u95ee\u9898 \u2014\u2014 \u6bd4\u5982\u751f\u4ea7\u8005\u5fc5\u987b\u5148\u751f\u4ea7&#xff0c;\u6d88\u8d39\u8005\u624d\u80fd\u6d88\u8d39&#xff1b;\u961f\u5217\u4e3a\u7a7a\u65f6\u6d88\u8d39\u8005\u4e0d\u80fd\u778e\u5fd9\u6d3b&#xff0c;\u961f\u5217\u4e3a\u6ee1\u65f6\u751f\u4ea7\u8005\u4e0d\u80fd\u786c\u585e\u6570\u636e\u3002\u8fd9\u79cd \u201c\u5728\u4fdd\u8bc1\u6570\u636e\u5b89\u5168\u7684\u524d\u63d0\u4e0b&#xff0c;\u8ba9\u7ebf\u7a0b\u6309\u9884\u5b9a\u987a\u5e8f\u6267\u884c\u201d \u7684\u673a\u5236&#xff0c;\u5c31\u662f\u7ebf\u7a0b\u540c\u6b65\u3002 \u5982\u679c\u8bf4\u7ebf\u7a0b\u4e92\u65a5\u662f\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/79726.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-03-02T14:42:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260302144213-69a5a1c5f23b3.gif\" \/>\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=\"16 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/79726.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/79726.html\",\"name\":\"\u3010Linux\u7cfb\u7edf\u7f16\u7a0b\u3011\uff08\u56db\u5341\u4e09\uff09\u7ebf\u7a0b\u540c\u6b65\u4e0a\u7bc7\uff1a\u4ece\u6761\u4ef6\u53d8\u91cf\u5230\u751f\u4ea7\u6d88\u8d39\u6a21\u578b\uff0c\u5403\u900f\u591a\u7ebf\u7a0b\u534f\u4f5c\u7cbe\u9ad3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-03-02T14:42:15+00:00\",\"dateModified\":\"2026-03-02T14:42:15+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/79726.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/79726.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/79726.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Linux\u7cfb\u7edf\u7f16\u7a0b\u3011\uff08\u56db\u5341\u4e09\uff09\u7ebf\u7a0b\u540c\u6b65\u4e0a\u7bc7\uff1a\u4ece\u6761\u4ef6\u53d8\u91cf\u5230\u751f\u4ea7\u6d88\u8d39\u6a21\u578b\uff0c\u5403\u900f\u591a\u7ebf\u7a0b\u534f\u4f5c\u7cbe\u9ad3\"}]},{\"@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":"\u3010Linux\u7cfb\u7edf\u7f16\u7a0b\u3011\uff08\u56db\u5341\u4e09\uff09\u7ebf\u7a0b\u540c\u6b65\u4e0a\u7bc7\uff1a\u4ece\u6761\u4ef6\u53d8\u91cf\u5230\u751f\u4ea7\u6d88\u8d39\u6a21\u578b\uff0c\u5403\u900f\u591a\u7ebf\u7a0b\u534f\u4f5c\u7cbe\u9ad3 - \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\/79726.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Linux\u7cfb\u7edf\u7f16\u7a0b\u3011\uff08\u56db\u5341\u4e09\uff09\u7ebf\u7a0b\u540c\u6b65\u4e0a\u7bc7\uff1a\u4ece\u6761\u4ef6\u53d8\u91cf\u5230\u751f\u4ea7\u6d88\u8d39\u6a21\u578b\uff0c\u5403\u900f\u591a\u7ebf\u7a0b\u534f\u4f5c\u7cbe\u9ad3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u524d\u8a00 \u5728\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u4e16\u754c\u91cc&#xff0c;\u7ebf\u7a0b\u4e92\u65a5\u89e3\u51b3\u4e86 \u201c\u591a\u4e2a\u7ebf\u7a0b\u62a2\u8d44\u6e90\u201d \u7684\u95ee\u9898&#xff0c;\u4fdd\u8bc1\u4e86\u4e34\u754c\u8d44\u6e90\u7684\u72ec\u5360\u8bbf\u95ee&#xff1b;\u4f46\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u6211\u4eec\u8fd8\u9700\u8981\u89e3\u51b3 \u201c\u7ebf\u7a0b\u95f4\u6709\u5e8f\u534f\u4f5c\u201d \u7684\u95ee\u9898 \u2014\u2014 \u6bd4\u5982\u751f\u4ea7\u8005\u5fc5\u987b\u5148\u751f\u4ea7&#xff0c;\u6d88\u8d39\u8005\u624d\u80fd\u6d88\u8d39&#xff1b;\u961f\u5217\u4e3a\u7a7a\u65f6\u6d88\u8d39\u8005\u4e0d\u80fd\u778e\u5fd9\u6d3b&#xff0c;\u961f\u5217\u4e3a\u6ee1\u65f6\u751f\u4ea7\u8005\u4e0d\u80fd\u786c\u585e\u6570\u636e\u3002\u8fd9\u79cd \u201c\u5728\u4fdd\u8bc1\u6570\u636e\u5b89\u5168\u7684\u524d\u63d0\u4e0b&#xff0c;\u8ba9\u7ebf\u7a0b\u6309\u9884\u5b9a\u987a\u5e8f\u6267\u884c\u201d \u7684\u673a\u5236&#xff0c;\u5c31\u662f\u7ebf\u7a0b\u540c\u6b65\u3002 \u5982\u679c\u8bf4\u7ebf\u7a0b\u4e92\u65a5\u662f","og_url":"https:\/\/www.wsisp.com\/helps\/79726.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-03-02T14:42:15+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260302144213-69a5a1c5f23b3.gif"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"16 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/79726.html","url":"https:\/\/www.wsisp.com\/helps\/79726.html","name":"\u3010Linux\u7cfb\u7edf\u7f16\u7a0b\u3011\uff08\u56db\u5341\u4e09\uff09\u7ebf\u7a0b\u540c\u6b65\u4e0a\u7bc7\uff1a\u4ece\u6761\u4ef6\u53d8\u91cf\u5230\u751f\u4ea7\u6d88\u8d39\u6a21\u578b\uff0c\u5403\u900f\u591a\u7ebf\u7a0b\u534f\u4f5c\u7cbe\u9ad3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-03-02T14:42:15+00:00","dateModified":"2026-03-02T14:42:15+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/79726.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/79726.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/79726.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Linux\u7cfb\u7edf\u7f16\u7a0b\u3011\uff08\u56db\u5341\u4e09\uff09\u7ebf\u7a0b\u540c\u6b65\u4e0a\u7bc7\uff1a\u4ece\u6761\u4ef6\u53d8\u91cf\u5230\u751f\u4ea7\u6d88\u8d39\u6a21\u578b\uff0c\u5403\u900f\u591a\u7ebf\u7a0b\u534f\u4f5c\u7cbe\u9ad3"}]},{"@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\/79726","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=79726"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/79726\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/79723"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=79726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=79726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=79726"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=79726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}