{"id":78289,"date":"2026-02-26T20:17:36","date_gmt":"2026-02-26T12:17:36","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/78289.html"},"modified":"2026-02-26T20:17:36","modified_gmt":"2026-02-26T12:17:36","slug":"linux%ef%bc%9a%e7%ba%bf%e7%a8%8b%e9%97%b4%e9%80%9a%e4%bf%a1","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/78289.html","title":{"rendered":"Linux\uff1a\u7ebf\u7a0b\u95f4\u901a\u4fe1"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"1.%E9%87%8D%E8%A6%81%E6%A6%82%E5%BF%B5-toc\" style=\"margin-left:0px\">1.\u91cd\u8981\u6982\u5ff5<\/p>\n<p id=\"2.%E7%BA%BF%E7%A8%8B%E9%97%B4%E9%80%9A%E4%BF%A1%E5%AE%9E%E7%8E%B0%E6%96%B9%E5%BC%8F%E2%80%94%E2%80%94%E6%9C%80%E7%AE%80%E5%8D%95%E7%9A%84%E6%96%B9%E6%B3%95%3A%E5%85%A8%E5%B1%80%E5%8F%98%E9%87%8F%2B%E9%94%81%EF%BC%88%E4%BA%92%E6%96%A5%E9%94%81%EF%BC%89-toc\" style=\"margin-left:0px\">2.\u7ebf\u7a0b\u95f4\u901a\u4fe1\u5b9e\u73b0\u65b9\u5f0f\u2014\u2014\u6700\u7b80\u5355\u7684\u65b9\u6cd5:\u5168\u5c40\u53d8\u91cf&#043;\u9501&#xff08;\u4e92\u65a5\u9501&#xff09;<\/p>\n<p id=\"3.%E5%8E%9F%E5%AD%90%E6%93%8D%E4%BD%9C-toc\" style=\"margin-left:0px\">3.\u539f\u5b50\u64cd\u4f5c<\/p>\n<p id=\"4.%E4%BA%92%E6%96%A5%E9%94%81-toc\" style=\"margin-left:0px\">4.\u4e92\u65a5\u9501&#xff08;Mutex&#xff09;<\/p>\n<p id=\"4.1%E4%BA%92%E6%96%A5%E9%94%81%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5-toc\" style=\"margin-left:40px\">4.1\u4e92\u65a5\u9501\u76f8\u5173\u6982\u5ff5<\/p>\n<p id=\"4.2%E4%BA%92%E6%96%A5%E9%94%81%E7%9B%B8%E5%85%B3%E5%87%BD%E6%95%B0%EF%BC%88pthread%20%E5%BA%93%EF%BC%89-toc\" style=\"margin-left:40px\">4.2\u4e92\u65a5\u9501\u76f8\u5173\u51fd\u6570&#xff08;pthread \u5e93&#xff09;<\/p>\n<p id=\"4.3%E4%BA%92%E6%96%A5%E9%94%81%E4%BD%BF%E7%94%A8%E6%AD%A5%E9%AA%A4-toc\" style=\"margin-left:40px\">4.3\u4e92\u65a5\u9501\u4f7f\u7528\u6b65\u9aa4<\/p>\n<p id=\"2.1%20%E5%AE%9A%E4%B9%89%E4%BA%92%E6%96%A5%E9%94%81-toc\" style=\"margin-left:80px\">4.3.1\u5b9a\u4e49\u4e92\u65a5\u9501<\/p>\n<p id=\"4.3.2%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BA%92%E6%96%A5%E9%94%81-toc\" style=\"margin-left:80px\">4.3.2\u521d\u59cb\u5316\u4e92\u65a5\u9501<\/p>\n<p id=\"4.3.3%E5%8A%A0%E9%94%81%EF%BC%88%E8%BF%9B%E5%85%A5%E4%B8%B4%E7%95%8C%E5%8C%BA%EF%BC%89-toc\" style=\"margin-left:80px\">4.3.3\u52a0\u9501&#xff08;\u8fdb\u5165\u4e34\u754c\u533a&#xff09;<\/p>\n<p id=\"2.4%C2%A0%E8%A7%A3%E9%94%81%EF%BC%88%E7%A6%BB%E5%BC%80%E4%B8%B4%E7%95%8C%E5%8C%BA%EF%BC%89-toc\" style=\"margin-left:80px\">4.3.4\u89e3\u9501&#xff08;\u79bb\u5f00\u4e34\u754c\u533a&#xff09;<\/p>\n<p id=\"2.5%C2%A0%E9%94%80%E6%AF%81%E4%BA%92%E6%96%A5%E9%94%81-toc\" style=\"margin-left:80px\">4.3.4\u9500\u6bc1\u4e92\u65a5\u9501<\/p>\n<p id=\"4.3.4%E9%94%80%E6%AF%81%E4%BA%92%E5%AE%9E%E6%88%98%E6%A1%88%E4%BE%8B-toc\" style=\"margin-left:80px\">4.3.4\u9500\u6bc1\u4e92\u5b9e\u6218\u6848\u4f8b<\/p>\n<p id=\"5.%E6%AD%BB%E9%94%81-toc\" style=\"margin-left:0px\">5.\u9501\u5728\u4f7f\u7528\u65f6\u6bd4\u8f83\u5e38\u89c1\u7684\u95ee\u9898\u2014\u2014\u6b7b\u9501<\/p>\n<p id=\"6.%E4%BF%A1%E5%8F%B7%E9%87%8F-toc\" style=\"margin-left:0px\">6.\u4fe1\u53f7\u91cf(Semaphore)<\/p>\n<p id=\"6.1%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5-toc\" style=\"margin-left:40px\">6.1\u4fe1\u53f7\u91cf\u76f8\u5173\u6982\u5ff5<\/p>\n<p id=\"6.2%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9A%84%E5%8E%9F%E7%90%86-toc\" style=\"margin-left:40px\">6.2\u4fe1\u53f7\u91cf\u7684\u539f\u7406<\/p>\n<p id=\"6.3%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9B%B8%E5%85%B3%E5%87%BD%E6%95%B0%EF%BC%88semaphore.h%E5%BA%93%EF%BC%89-toc\" style=\"margin-left:40px\">6.3\u4fe1\u53f7\u91cf\u76f8\u5173\u51fd\u6570&#xff08;semaphore.h\u5e93&#xff09;<\/p>\n<p id=\"6.4%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9A%84%E4%BD%BF%E7%94%A8%E6%AD%A5%E9%AA%A4-toc\" style=\"margin-left:40px\">6.4\u4fe1\u53f7\u91cf\u7684\u4f7f\u7528\u6b65\u9aa4<\/p>\n<p id=\"6.4.1%E5%AE%9A%E4%B9%89%E4%BF%A1%E5%8F%B7%E9%87%8F-toc\" style=\"margin-left:80px\">6.4.1\u5b9a\u4e49\u4fe1\u53f7\u91cf<\/p>\n<p id=\"6.4.2%C2%A0%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BF%A1%E5%8F%B7%E9%87%8F-toc\" style=\"margin-left:80px\">6.4.2\u00a0\u521d\u59cb\u5316\u4fe1\u53f7\u91cf<\/p>\n<p id=\"6.4.3%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9A%84%E6%93%8D%E4%BD%9C%E2%80%94%E2%80%94%E7%94%B3%E8%AF%B7%E8%B5%84%E6%BA%90-toc\" style=\"margin-left:80px\">6.4.3\u4fe1\u53f7\u91cf\u7684\u64cd\u4f5c\u2014\u2014\u7533\u8bf7\u8d44\u6e90<\/p>\n<p id=\"6.4.4%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9A%84%E6%93%8D%E4%BD%9C%E2%80%94%E2%80%94%E9%87%8A%E6%94%BE%E8%B5%84%E6%BA%90-toc\" style=\"margin-left:80px\">6.4.4\u4fe1\u53f7\u91cf\u7684\u64cd\u4f5c\u2014\u2014\u91ca\u653e\u8d44\u6e90<\/p>\n<p id=\"6.4.5%E9%94%80%E6%AF%81%E4%BF%A1%E5%8F%B7%E9%87%8F-toc\" style=\"margin-left:80px\">6.4.5\u9500\u6bc1\u4fe1\u53f7\u91cf<\/p>\n<p id=\"4.%E4%BF%A1%E5%8F%B7%E9%87%8F%E5%90%8C%E6%AD%A5%E5%AE%9E%E6%88%98%E7%A4%BA%E4%BE%8B-toc\" style=\"margin-left:80px\">6.4.6\u4fe1\u53f7\u91cf\u540c\u6b65\u5b9e\u6218\u793a\u4f8b<\/p>\n<hr id=\"hr-toc\" \/>\n<h2 id=\"1.%E9%87%8D%E8%A6%81%E6%A6%82%E5%BF%B5\">1.\u91cd\u8981\u6982\u5ff5<\/h2>\n<p>\u2460\u4e34\u754c\u8d44\u6e90\u200b&#xff1a;\u4e00\u6b21\u4ec5\u5141\u8bb8\u4e00\u4e2a\u4efb\u52a1&#xff08;\u7ebf\u7a0b\/\u8fdb\u7a0b&#xff09;\u8bbf\u95ee\u7684\u5171\u4eab\u8d44\u6e90&#xff08;\u6bd4\u5982\u5168\u5c40\u53d8\u91cf\u3001\u6587\u4ef6\u3001\u786c\u4ef6\u8bbe\u5907&#xff09;\u3002\u662f\u9700\u8981\u88ab\u4fdd\u62a4\u7684\u5bf9\u8c61<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u4f8b&#xff1a;\u552f\u4e00\u7684\u5751\u4f4d \/ \u5171\u4eab\u7684\u94f6\u884c\u8d26\u6237\u200b\/\u591a\u7ebf\u7a0b\u7a0b\u5e8f\u4e2d\u7684\u5171\u4eab\u53d8\u91cf\u3001\u5171\u4eab\u6587\u4ef6\u3001\u5171\u4eab\u6570\u636e\u5e93\u8fde\u63a5\u3001\u5171\u4eab\u786c\u4ef6&#xff08;\u5982\u6253\u5370\u673a&#xff09;\u3002<\/p>\n<\/p>\n<p>\u2461\u4e34\u754c\u533a&#xff08;\u5373\u4e34\u754c\u4ee3\u7801&#xff09;&#xff1a;\u8bbf\u95ee\u548c\u64cd\u4f5c\u4e34\u754c\u8d44\u6e90\u7684\u90a3\u6bb5\u4ee3\u7801\u3002\u200b\u3010\u4e34\u754c\u4ee3\u7801\u6216\u4e34\u754c\u533a\u4e0d\u53ef\u80fd\u540c\u65f6\u88abCPU\u4efb\u52a1\u6267\u884c\u3011<\/p>\n<\/p>\n<p>\u2462\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898&#xff1a;\u200b\u5f53\u591a\u4e2a\u7ebf\u7a0b\u672a\u53d7\u63a7\u5236\u5730\u5e76\u53d1\u8bbf\u95ee\u540c\u4e00\u4e34\u754c\u8d44\u6e90\u65f6&#xff0c;\u5bfc\u81f4\u7a0b\u5e8f\u7ed3\u679c\u4e0d\u53ef\u9884\u6d4b\u3001\u6570\u636e\u635f\u574f\u6216\u903b\u8f91\u9519\u8bef\u7684\u95ee\u9898\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u6bd4\u55bb&#xff1a;\u4e89\u62a2\u5f15\u53d1\u7684\u6df7\u4e71 \/ \u8d26\u6237\u91d1\u989d\u51fa\u9519\u200b<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u539f\u56e0&#xff1a;\u7ebf\u7a0b\u7684\u6267\u884c\u987a\u5e8f\u548c\u65f6\u673a\u7531\u64cd\u4f5c\u7cfb\u7edf\u8c03\u5ea6&#xff0c;\u5145\u6ee1\u4e0d\u786e\u5b9a\u6027\u3002<\/p>\n<\/p>\n<h2 id=\"2.%E7%BA%BF%E7%A8%8B%E9%97%B4%E9%80%9A%E4%BF%A1%E5%AE%9E%E7%8E%B0%E6%96%B9%E5%BC%8F%E2%80%94%E2%80%94%E6%9C%80%E7%AE%80%E5%8D%95%E7%9A%84%E6%96%B9%E6%B3%95%3A%E5%85%A8%E5%B1%80%E5%8F%98%E9%87%8F%2B%E9%94%81%EF%BC%88%E4%BA%92%E6%96%A5%E9%94%81%EF%BC%89\">2.\u7ebf\u7a0b\u95f4\u901a\u4fe1\u5b9e\u73b0\u65b9\u5f0f\u2014\u2014\u6700<span style=\"background-color:#dad5e9\">\u7b80\u5355\u7684\u65b9\u6cd5:\u5168\u5c40\u53d8\u91cf&#043;\u9501&#xff08;\u4e92\u65a5\u9501&#xff09;<\/span><\/h2>\n<p>1.\u4e00\u4e2a\u8fdb\u7a0b\u7a7a\u95f4\u5185\u90e8\u7684\u6240\u6709\u7ebf\u7a0b\u5171\u4eab\u6570\u636e\u6bb5\u548c\u5806\u533a&#xff0c;\u6240\u4ee5\u5168\u5c40\u53d8\u91cf\u3001\u9759\u6001\u53d8\u91cf\u3001\u5806\u533a\u7a7a\u95f4\u90fd\u662f\u5171\u4eab\u7684&#xff0c;\u53ef\u4ee5\u5229\u7528\u8fd9\u4e9b\u7a7a\u95f4\u901a\u4fe1 2.\u591a\u7ebf\u7a0b\u64cd\u4f5c\u5168\u5c40\u53d8\u91cf\u7a7a\u95f4\u65f6\u4f1a\u5f15\u5165\u8d44\u6e90\u7ade\u4e89<\/p>\n<p>3.\u591a\u7ebf\u7a0b\u8981\u907f\u514d\u5f15\u5165\u8d44\u6e90\u7ade\u4e89\u53ef\u4ee5\u901a\u8fc7\u52a0\u4e92\u65a5\u9501\u89e3\u51b3\u3010\u5e94\u7528\u5c42\u7f16\u7a0b\u7528\u4e92\u65a5\u9501&#xff0c;\u5185\u6838\u7f16\u7a0b\u7528\u5185\u65cb\u9501\u3011<\/p>\n<p>4.\u4e92\u65a5\u7684\u6838\u5fc3\u662f\u6392\u4ed6\u6027\u8bbf\u95ee&#xff1a;\u540c\u4e00\u65f6\u523b&#xff0c;\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u64cd\u4f5c\u4e34\u754c\u8d44\u6e90\u3002<\/p>\n<h2 id=\"3.%E5%8E%9F%E5%AD%90%E6%93%8D%E4%BD%9C\">3.\u539f\u5b50\u64cd\u4f5c<\/h2>\n<p>\u6982\u5ff5&#xff1a;\u4e0d\u4f1a\u88abCPU\u4efb\u52a1\u8c03\u5ea6\u6253\u65ad\u7684\u4e00\u6b21\u6700\u5c0f\u7684\u64cd\u4f5c\u79f0\u4e3a\u539f\u5b50\u64cd\u4f5c&#xff08;\u5373\u4e00\u6b21\u673a\u5668\u7801&#xff09;<\/p>\n<h2 id=\"4.%E4%BA%92%E6%96%A5%E9%94%81\">4.\u4e92\u65a5\u9501&#xff08;Mutex&#xff09;<\/h2>\n<h3 id=\"4.1%E4%BA%92%E6%96%A5%E9%94%81%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5\">4.1\u4e92\u65a5\u9501\u76f8\u5173\u6982\u5ff5<\/h3>\n<p>1.\u4e92\u65a5\u6982\u5ff5&#xff1a;\u4e92\u65a5\u7684\u6838\u5fc3\u662f\u6392\u4ed6\u6027\u8bbf\u95ee&#xff0c;\u4e3a\u907f\u514d\u591a\u7ebf\u7a0b\u8d44\u6e90\u7ade\u4e89&#xff0c;\u540c\u4e00\u5b8f\u89c2\u65f6\u523b&#xff0c;\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u64cd\u4f5c\u4e34\u754c\u8d44\u6e90\u3002&#xff08;<span style=\"background-color:#f9eda6\">\u4e92\u65a5\u9501&#xff0c;\u5219&#034;\u8fd9\u628a\u9501\u53ea\u80fd\u4e00\u4e2a\u4eba\u7528&#034;<\/span>&#xff09;<\/p>\n<p>2.\u4e92\u65a5\u9501\u4f7f\u7528\u65b9\u6cd5&#xff1a;\u914d\u5408\u8d44\u6e90\u4f7f\u7528&#xff0c;\u4f7f\u7528\u8d44\u6e90\u524d\u52a0\u9501&#xff0c;\u4f7f\u7528\u8d44\u6e90\u7ed3\u675f\u540e\u89e3\u9501<\/p>\n<p>3.\u52a0\u9501\u540e&#xff0c;\u65e0\u6cd5\u518d\u6b21\u52a0\u9501&#xff0c;\u5fc5\u987b\u963b\u585e\u7b49\u5f85\u89e3\u9501\u540e\u624d\u80fd\u7ee7\u7eed\u52a0\u9501<\/p>\n<h3 id=\"4.2%E4%BA%92%E6%96%A5%E9%94%81%E7%9B%B8%E5%85%B3%E5%87%BD%E6%95%B0%EF%BC%88pthread%20%E5%BA%93%EF%BC%89\">4.2\u4e92\u65a5\u9501\u76f8\u5173\u51fd\u6570&#xff08;pthread \u5e93&#xff09;<\/h3>\n<p>\u76f8\u5173\u51fd\u6570\u3010\u51fd\u6570&#xff1a;\u5c31\u56db\u4e2a\u3011\u3010\u5e94\u7528&#xff1a;\u5c31\u4e00\u4e2a\u2014\u2014\u907f\u514d\u8d44\u6e90\u7ade\u4e89\u95ee\u9898\u3011<\/p>\n<p>\u4e92\u65a5\u9501\u7684\u521d\u59cb\u5316\u00a0 &#xff1a;pthread_mutex_init<\/p>\n<p>\u4e92\u65a5\u9501\u7684\u9500\u6bc1\u00a0 \u00a0 \u00a0&#xff1a;pthread_mutex_destroy<\/p>\n<p>\u4e92\u65a5\u9501\u7684\u52a0\u9501\u00a0 \u00a0 \u00a0&#xff1a;pthread_mutex_lock<\/p>\n<p>\u4e92\u65a5\u9501\u7684\u89e3\u9501\u00a0 \u00a0 \u00a0&#xff1a;pthread_mutex_unlock<\/p>\n<p>pthread_mutex_init<\/p>\n<p>\u539f\u578b&#xff1a;int pthread_mutex_init(pthread_mutex_t *restrict mutex,const pthread_mutexattr_t*restrict attr); \u529f\u80fd:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e92\u65a5\u9501\u7684\u521d\u59cb\u5316 \u53c2\u6570: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mutex:\u4e92\u65a5\u9501\u7a7a\u95f4\u9996\u5730\u5740 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0attr:\u4e92\u65a5\u9501\u7684\u5c5e\u6027&#xff0c;\u9ed8\u8ba4\u4f20NULL<\/p>\n<p>\u8fd4\u56de\u503c: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6210\u529f\u8fd4\u56de0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5931\u8d25\u8fd4\u56de\u975e0<\/p>\n<p>pthread_mutex_destroy<\/p>\n<p>\u539f\u578b&#xff1a;int pthread_mutex_destroy(pthread_mutex_t *mutex); \u529f\u80fd:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e92\u65a5\u9501\u7684\u9500\u6bc1 \u53c2\u6570: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mutex:\u4e92\u65a5\u9501\u7a7a\u95f4\u9996\u5730\u5740<\/p>\n<p>\u8fd4\u56de\u503c: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6210\u529f\u8fd4\u56de0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5931\u8d25\u8fd4\u56de\u975e0<\/p>\n<p>pthread mutex_ lock<\/p>\n<p>\u539f\u578b&#xff1a;int pthread_mutex_lock(pthread_mutex_t *mutex); \u529f\u80fd:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e92\u65a5\u9501\u52a0\u9501<\/p>\n<ul>\n<li>\u7528\u6307\u5b9a\u7684\u4e92\u65a5\u9501\u5f00\u59cb\u52a0\u9501\u4ee3\u7801&#xff0c;\u6210\u529f\u5219\u8fdb\u5165\u4e34\u754c\u533a&#xff1b;\u5931\u8d25\u5219\u963b\u585e\u7b49\u5f85\u3002<\/li>\n<li>\u6ce8\u610f&#xff1a;\u52a0\u9501\u540e\u7684\u4ee3\u7801\u662f\u539f\u5b50\u64cd\u4f5c&#xff08;\u7ebf\u7a0b\u8c03\u5ea6\u4e0d\u4f1a\u6253\u65ad\u8fd9\u6bb5\u4ee3\u7801&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u53c2\u6570: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mutex:\u4e92\u65a5\u9501\u7a7a\u95f4\u9996\u5730\u5740<\/p>\n<p>\u8fd4\u56de\u503c: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6210\u529f\u8fd4\u56de0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5931\u8d25\u8fd4\u56de\u975e0<\/p>\n<p>pthread mutex_unlock<\/p>\n<p>\u539f\u578b&#xff1a;int pthread_mutex_lock(pthread_mutex_t *mutex); \u529f\u80fd:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e92\u65a5\u9501\u89e3\u9501<\/p>\n<ul>\n<li>\u5c06\u6307\u5b9a\u7684\u4e92\u65a5\u9501\u89e3\u9501&#xff0c;\u8ba9\u5176\u4ed6\u7ebf\u7a0b\u53ef\u4ee5\u7ade\u4e89\u3002\u89e3\u9501\u4e4b\u540e\u4ee3\u7801\u4e0d\u518d\u6392\u4ed6\u8bbf\u95ee\u3002<\/li>\n<li>\u6ce8\u610f&#xff1a;\u52a0\u9501\u548c\u89e3\u9501\u5fc5\u987b\u6210\u5bf9\u51fa\u73b0&#xff0c;\u4e14\u8981\u5728\u540c\u4e00\u4e2a\u7ebf\u7a0b\u4e2d\u6267\u884c\u3002<\/li>\n<\/ul>\n<p>\u53c2\u6570: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mutex:\u4e92\u65a5\u9501\u7a7a\u95f4\u9996\u5730\u5740<\/p>\n<p>\u8fd4\u56de\u503c: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6210\u529f\u8fd4\u56de0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5931\u8d25\u8fd4\u56de\u975e0<\/p>\n<h3 id=\"4.3%E4%BA%92%E6%96%A5%E9%94%81%E4%BD%BF%E7%94%A8%E6%AD%A5%E9%AA%A4\">4.3\u4e92\u65a5\u9501\u4f7f\u7528\u6b65\u9aa4<\/h3>\n<p>Linux\u00a0\u4e0b\u7528 pthread_mutex_t \u5b9e\u73b0\u4e92\u65a5\u9501&#xff0c;\u6b65\u9aa4\u662f&#xff1a;\u5b9a\u4e49\u2192\u521d\u59cb\u5316\u2192\u52a0\u9501\u2192\u89e3\u9501\u2192\u9500\u6bc1\u3002<\/p>\n<h4 id=\"2.1%20%E5%AE%9A%E4%B9%89%E4%BA%92%E6%96%A5%E9%94%81\">4.3.1\u5b9a\u4e49\u4e92\u65a5\u9501<\/h4>\n<p>#include &lt;pthread.h&gt;<br \/>\n\/\/ \u5b9a\u4e49\u5168\u5c40\/\u5171\u4eab\u7684\u4e92\u65a5\u9501<br \/>\npthread_mutex_t lock; <\/p>\n<h4 id=\"4.3.2%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BA%92%E6%96%A5%E9%94%81\">4.3.2\u521d\u59cb\u5316\u4e92\u65a5\u9501<\/h4>\n<p>\/\/ \u793a\u4f8b<br \/>\npthread_mutex_init(&amp;lock, NULL); <\/p>\n<h4 id=\"4.3.3%E5%8A%A0%E9%94%81%EF%BC%88%E8%BF%9B%E5%85%A5%E4%B8%B4%E7%95%8C%E5%8C%BA%EF%BC%89\">4.3.3\u52a0\u9501&#xff08;\u8fdb\u5165\u4e34\u754c\u533a&#xff09;<\/h4>\n<p>\/\/ \u793a\u4f8b<br \/>\npthread_mutex_lock(&amp;lock); <\/p>\n<h4 id=\"2.4%C2%A0%E8%A7%A3%E9%94%81%EF%BC%88%E7%A6%BB%E5%BC%80%E4%B8%B4%E7%95%8C%E5%8C%BA%EF%BC%89\">4.3.4\u89e3\u9501&#xff08;\u79bb\u5f00\u4e34\u754c\u533a&#xff09;<\/h4>\n<p>\/\/ \u793a\u4f8b<br \/>\npthread_mutex_unlock(&amp;lock); <\/p>\n<h4 id=\"2.5%C2%A0%E9%94%80%E6%AF%81%E4%BA%92%E6%96%A5%E9%94%81\">4.3.4\u9500\u6bc1\u4e92\u65a5\u9501<\/h4>\n<p>\/\/ \u793a\u4f8b<br \/>\npthread_mutex_destroy(&amp;lock); <\/p>\n<h4 id=\"4.3.4%E9%94%80%E6%AF%81%E4%BA%92%E5%AE%9E%E6%88%98%E6%A1%88%E4%BE%8B\">4.3.4\u9500\u6bc1\u4e92\u5b9e\u6218\u6848\u4f8b<\/h4>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;  \/\/ \u7528\u4e8e\u7ed9\u6307\u9488\u7f6e\u7a7a<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;pthread.h&gt; \/\/\u7528\u4e8e\u7ebf\u7a0b\u76f8\u5173\u51fd\u6570<\/p>\n<p>int Num &#061; 0;<br \/>\npthread_mutex_t lock;<\/p>\n<p>void* threadfun1(void* arg)<br \/>\n{<br \/>\n    printf(&#034;\u7ebf\u7a0b\u5f00\u59cb\u6267\u884c&#xff08;TID&#xff1a;%#x&#xff09;\\\\n&#034;,(unsigned int)pthread_self());\/\/%#x:\u5341\u516d\u8fdb\u5236\u6570&#xff0c;\u5c0f\u5199\u5b57\u6bcd&#xff0c;\u5e76\u81ea\u52a8\u6dfb\u52a0 0x\u524d\u7f00\u3002<\/p>\n<p>    while(1)  \/\/\u6b7b\u5faa\u73af\u662f\u4e3a\u4e86\u9632\u6b62\u8fdb\u7a0b\u7ed3\u675f&#xff0c;\u56e0\u4e3a\u8fdb\u7a0b\u4e0d\u5728\u7ebf\u7a0b\u4e5f\u4e0d\u5728<br \/>\n    {<br \/>\n        pthread_mutex_lock(&amp;lock);<br \/>\n        Num &#061; 100;<br \/>\n        printf(&#034;Num &#061; %d\\\\n&#034;,Num);<br \/>\n        pthread_mutex_unlock(&amp;lock);<br \/>\n    }<br \/>\n    return NULL;<br \/>\n}<\/p>\n<p>void* threadfun2(void* arg)<br \/>\n{<br \/>\n    printf(&#034;\u7ebf\u7a0b\u5f00\u59cb\u6267\u884c&#xff08;TID&#xff1a;%#x&#xff09;\\\\n&#034;,(unsigned int)pthread_self());\/\/%#x:\u5341\u516d\u8fdb\u5236\u6570&#xff0c;\u5c0f\u5199\u5b57\u6bcd&#xff0c;\u5e76\u81ea\u52a8\u6dfb\u52a0 0x\u524d\u7f00\u3002<\/p>\n<p>    while(1)  \/\/\u6b7b\u5faa\u73af\u662f\u4e3a\u4e86\u9632\u6b62\u8fdb\u7a0b\u7ed3\u675f&#xff0c;\u56e0\u4e3a\u8fdb\u7a0b\u4e0d\u5728\u7ebf\u7a0b\u4e5f\u4e0d\u5728<br \/>\n    {<br \/>\n        pthread_mutex_lock(&amp;lock);<br \/>\n        Num &#061; 200;<br \/>\n        printf(&#034;Num &#061; %d\\\\n&#034;,Num);<br \/>\n        pthread_mutex_unlock(&amp;lock);<br \/>\n    }<br \/>\n    return NULL;<br \/>\n}<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n    int ret1 &#061;  0;<br \/>\n    int ret2 &#061;  0;    <\/p>\n<p>    pthread_t tid1;<br \/>\n    pthread_t tid2;<\/p>\n<p>    pthread_mutex_init(&amp;lock,NULL); \/\/\u4e0d\u914d\u7f6e&#xff0c;\u6240\u4ee5\u7f6e\u7a7a<br \/>\n    ret1 &#061;pthread_create(&amp;tid1,NULL,threadfun1,NULL);\/\/\u521b\u5efa\u7ebf\u7a0b1<br \/>\n    ret2 &#061;pthread_create(&amp;tid2,NULL,threadfun2,NULL);<br \/>\n#if 1<br \/>\n    if(ret1 !&#061; 0 || ret2 !&#061; 0)<br \/>\n    {<br \/>\n        perror(&#034;fail to pthread_create&#034;);<br \/>\n        return -1;<br \/>\n    }<br \/>\n#endif<br \/>\n    pthread_join(tid1,NULL);\/\/\u963b\u585e\u56de\u6536\u7ebf\u7a0b<br \/>\n    pthread_join(tid2,NULL);<\/p>\n<p>    pthread_mutex_destroy(&amp;lock);\/\/\u9501\u7684\u9500\u6bc1<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<p>\u6ce8\u610f&#xff1a;<\/p>\n<p>\u2460\u8981\u52a0\u9501\u5c31\u5fc5\u987b\u5404\u8fdb\u7a0b\u90fd\u52a0\u9501\u624d\u80fd\u5b9e\u73b0\u4f60\u60f3\u8981\u7684\u529f\u80fd&#xff08;\u5426\u5219\u4f60\u633a\u5b88\u89c4\u77e9\u4e0a\u5395\u6240\u4e0a\u9501&#xff0c;\u4f46\u662f\u522b\u4eba\u4e0d\u5b88\u89c4\u77e9\u4e00\u811a\u628a\u95e8\u8e39\u5f00&#xff09;<\/p>\n<p>\u2461\u4e92\u65a5\u9501\u53ea\u80fd\u89e3\u51b3\u8d44\u6e90\u7ade\u4e89&#xff0c;\u4f46\u662f\u8c01\u5148\u7528\u8c01\u540e\u7528\u4e0d\u77e5\u9053&#xff08;\u4e92\u65a5\u9501\u4e0d\u7b49\u4e8e\u540c\u6b65&#xff09;<\/p>\n<p>\u2462\u7b2c\u4e8c\u4e2a\u4eba\u53ea\u6709\u5f53\u7b2c\u4e00\u4e2a\u4eba\u89e3\u5b8c\u9501&#xff0c;\u4e14\u4efb\u52a1\u8c03\u5ea6\u521a\u597d\u5230\u8fbe\u7b2c\u4e8c\u4e2a\u4eba\u65f6&#xff0c;\u7b2c\u4e8c\u4e2a\u4eba\u624d\u80fd\u62ff\u5230\u9501<\/p>\n<h2 id=\"5.%E6%AD%BB%E9%94%81\">5.\u9501\u5728\u4f7f\u7528\u65f6\u6bd4\u8f83\u5e38\u89c1\u7684\u95ee\u9898\u2014\u2014\u6b7b\u9501<\/h2>\n<p>\u6b7b\u9501\u7684\u7ecf\u5178\u793a\u4f8b&#xff08;\u54f2\u5b66\u5bb6\u5c31\u9910\u95ee\u9898&#xff09;<\/p>\n<p> \/\/ 5\u4e2a\u54f2\u5b66\u5bb6&#xff0c;5\u652f\u7b77\u5b50&#xff08;5\u628a\u9501&#xff09;<br \/>\n\/\/ \u6bcf\u4e2a\u54f2\u5b66\u5bb6\u9700\u8981\u540c\u65f6\u62ff\u8d77\u5de6\u53f3\u4e24\u652f\u7b77\u5b50\u624d\u80fd\u5403\u996d<\/p>\n<p>\u54f2\u5b66\u5bb6A&#xff1a;\u62ff\u8d77\u5de6\u7b77\u5b50 \u2192 \u7b49\u5f85\u53f3\u7b77\u5b50&#xff08;\u88abB\u62ff\u7740&#xff09;<br \/>\n\u54f2\u5b66\u5bb6B&#xff1a;\u62ff\u8d77\u5de6\u7b77\u5b50 \u2192 \u7b49\u5f85\u53f3\u7b77\u5b50&#xff08;\u88abC\u62ff\u7740&#xff09;<br \/>\n\u54f2\u5b66\u5bb6C&#xff1a;\u62ff\u8d77\u5de6\u7b77\u5b50 \u2192 \u7b49\u5f85\u53f3\u7b77\u5b50&#xff08;\u88abD\u62ff\u7740&#xff09;<br \/>\n\u54f2\u5b66\u5bb6D&#xff1a;\u62ff\u8d77\u5de6\u7b77\u5b50 \u2192 \u7b49\u5f85\u53f3\u7b77\u5b50&#xff08;\u88abE\u62ff\u7740&#xff09;<br \/>\n\u54f2\u5b66\u5bb6E&#xff1a;\u62ff\u8d77\u5de6\u7b77\u5b50 \u2192 \u7b49\u5f85\u53f3\u7b77\u5b50&#xff08;\u88abA\u62ff\u7740&#xff09;\u2190 \u5f62\u6210\u5faa\u73af\u7b49\u5f85&#xff01; <\/p>\n<p>\u6982\u5ff5&#xff1a;\u6b7b\u9501\u662f\u4e24\u4e2a\u6216\u66f4\u591a \u8fdb\u7a0b\/\u7ebf\u7a0b \u5728\u6267\u884c\u8fc7\u7a0b\u4e2d&#xff0c;\u56e0\u7ade\u4e89\u5171\u4eab\u8d44\u6e90\u800c\u9020\u6210\u7684\u4e00\u79cd\u76f8\u4e92\u7b49\u5f85\u7684\u72b6\u6001\u3002\u82e5\u65e0\u5916\u529b\u5e72\u6d89&#xff0c;\u5b83\u4eec\u90fd\u5c06\u65e0\u6cd5\u7ee7\u7eed\u5411\u524d\u63a8\u8fdb\u3002<\/p>\n<p>\u539f\u56e0&#xff1a;\u591a\u4efb\u52a1\u901a\u4fe1\u8fc7\u7a0b\u4e2d\u7531\u4e8e\u52a0\u9501\u5bfc\u81f4<\/p>\n<\/p>\n<p>\u6b7b\u9501\u4ea7\u751f\u7684\u56db\u4e2a\u5145\u5206\u6761\u4ef6&#xff1a;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u2460\u4e92\u65a5\u6761\u4ef6&#xff08;\u8d44\u6e90\u4e00\u6b21\u53ea\u80fd\u4e00\u4e2a\u4eba\u7528&#xff0c;\u6211\u52a0\u95011\u4f60\u5c31\u4e0d\u80fd\u52a0\u95011\u4e86&#xff0c;\u4e00\u4e2a\u9501\u53ea\u80fd\u88ab\u4e00\u4e2a\u4eba\u5360\u7528&#xff09;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u2461\u4e0d\u53ef\u5265\u593a\u6761\u4ef6&#xff08;\u8fdb\u7a0b\/\u7ebf\u7a0b\u5df2\u83b7\u5f97\u7684\u8d44\u6e90&#xff0c;\u5728\u672a\u4f7f\u7528\u5b8c\u4e4b\u524d\u4e0d\u80fd\u88ab\u5f3a\u5236\u5265\u593a\u3002\u4e0d\u80fd\u62a2\u522b\u4eba\u6b63\u5728\u7528\u7684\u8d44\u6e90&#xff09;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u2462\u8bf7\u6c42\u4fdd\u6301&#xff08;\u62ff\u4e0d\u5230\u9501&#xff0c;\u963b\u585e\u7b49\u5f85&#xff0c;\u8fc7\u4e00\u6bb5\u65f6\u95f4\u7ee7\u7eed\u8bf7\u6c42\u62ff\u9501&#xff09;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u2463\u5faa\u73af\u7b49\u5f85&#xff08;\u82e5\u5e72\u8fdb\u7a0b\u4e4b\u95f4\u5f62\u6210\u4e00\u79cd\u5934\u5c3e\u76f8\u63a5\u7684\u5faa\u73af\u7b49\u5f85\u94fe\u8d44\u6e90\u5173\u7cfb\u3002&#xff09;<\/p>\n<\/p>\n<p>\u89e3\u51b3\u6b7b\u9501&#xff08;\u7834\u574f\u5145\u5206\u6761\u4ef6\u5373\u53ef&#xff0c;\u2460\u2461\u662f\u9501\u7684\u57fa\u672c\u7279\u6027&#xff0c;\u65e0\u6cd5\u7834\u574f&#xff0c;\u53ea\u80fd\u7834\u574f\u2462\u6216\u2463&#xff09;&#xff1a;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u2460\u7528pthread_mutex_trylock\u907f\u514d\u6c38\u4e45\u963b\u585e\u66ff\u4ee3pthread_mutex_lock\u3010\u4f5c\u7528&#xff1a;\u5c1d\u8bd5\u52a0\u9501&#xff0c;\u80fd\u52a0\u5c31\u52a0&#xff0c;\u52a0\u4e0d\u4e0a\u5c31\u4e0d\u52a0&#xff0c;\u8df3\u8fc7\u52a0\u9501\u8fd9\u91cc&#xff0c;\u800c\u53bb\u6267\u884c\u540e\u8fb9\u7a0b\u5e8f&#xff0c;\u9632\u6b62\u4e86\u7a0b\u5e8f\u5361\u6b7b\u3011\u3010\u539f\u7406&#xff1a;\u7834\u574f\u201c\u8bf7\u6c42\u4fdd\u6301\u201d\u6761\u4ef6\u3011<\/p>\n<p> \/\/ \u4f7f\u7528pthread_mutex_trylock\u907f\u514d\u6c38\u4e45\u963b\u585e<br \/>\nif (pthread_mutex_trylock(&amp;lock) &#061;&#061; 0) {<br \/>\n    \/\/ \u6210\u529f\u83b7\u5f97\u9501<br \/>\n    \/\/ &#8230; \u6267\u884c\u64cd\u4f5c<br \/>\n    pthread_mutex_unlock(&amp;lock);<br \/>\n} else {<br \/>\n    \/\/ \u83b7\u53d6\u5931\u8d25&#xff0c;\u6267\u884c\u66ff\u4ee3\u903b\u8f91\u6216\u7a0d\u540e\u91cd\u8bd5<br \/>\n    \/\/ \u4e0d\u4f1a\u963b\u585e\u5728\u8fd9\u91cc<br \/>\n} <\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u2461\u6240\u6709\u7ebf\u7a0b\u52a0\u9501\u987a\u5e8f\u4fdd\u6301\u4e00\u81f4<span style=\"background-color:#f9eda6\">\u3010\u6700\u5b9e\u7528&#xff0c;\u80fd\u5f7b\u5e95\u9884\u9632\u6b7b\u9501&#xff0c;\u9884\u9632\u4f18\u4e8e\u68c0\u6d4b\u3011<\/span>&#xff08;\u7ebf\u7a0b1\u662f\u5148\u52a0\u95011&#xff0c;\u518d\u52a0\u95012&#xff0c;\u90a3\u4e48\u7ebf\u7a0b2\u4e5f\u8981\u52a0\u95011&#xff0c;\u518d\u52a0\u95012\u3002\u5426\u5219\u5bfc\u81f4\u6b7b\u9501&#xff09;<\/p>\n<p><span style=\"background-color:#fbd4d0\">\u8f6f\u4ef6\u7f16\u7801\u4e2d&#xff0c;<\/span><span style=\"background-color:#fbd4d0\">\u963b\u585e\u4e00\u5b9a\u8981\u907f\u514d&#xff08;\u4f7f\u7528\u5e26\u5ef6\u65f6\u6216\u5e26\u5c1d\u8bd5try\u7684\u51fd\u6570\u63a5\u53e3&#xff09;<\/span><span style=\"background-color:#fbd4d0\">&#xff0c;\u56e0\u4e3a\u975e\u5e38\u5bb9\u6613\u5bfc\u81f4\u5361\u6b7b\u3002\u6216\u8005\u52a0\u4e0a\u8d85\u65f6\u9000\u51fa<\/span><\/p>\n<\/p>\n<h3 id=\"\"><\/h3>\n<h2 id=\"6.%E4%BF%A1%E5%8F%B7%E9%87%8F\">6.\u4fe1\u53f7\u91cf(Semaphore)<\/h2>\n<h3 id=\"6.1%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5\">6.1\u4fe1\u53f7\u91cf\u76f8\u5173\u6982\u5ff5<\/h3>\n<p>\u4fe1\u53f7\u91cf\u7684\u6982\u5ff5&#xff1a;\u4fe1\u53f7\u91cf\u662f\u4e00\u4e2a\u8d44\u6e90&#xff0c;\u8d44\u6e90\u53ef\u4ee5\u521d\u59cb\u5316\u3001\u9500\u6bc1\u3001\u7533\u8bf7\u548c\u91ca\u653e<\/p>\n<p>\u5982\u679c\u8d44\u6e90\u6570&gt;0&#xff0c;\u5219\u7533\u8bf7\u8d44\u6e90\u662f\u8ba9\u8d44\u6e90\u6570-1<\/p>\n<p>\u5982\u679c\u8d44\u6e90\u6570\u4e3a0&#xff0c;\u7533\u8bf7\u8d44\u6e90\u65f6\u5219\u4f1a\u963b\u585e\u7b49\u5f85&#xff0c;\u7b49\u5f85\u6709\u4eba\u91ca\u653e\u8d44\u6e90&#xff0c;\u624d\u80fd\u7533\u8bf7\u62ff\u5230\u8d44\u6e90<\/p>\n<p>\u91ca\u653e\u4e0d\u4f1a\u963b\u5be8&#xff0c;\u8ba9\u8d44\u6e90\u6570&#043;1<\/p>\n<p>\u540c\u6b65\u4e0e\u5f02\u6b65<\/p>\n<p>1.\u540c\u6b65:\u62e5\u6709\u4e25\u683c\u7684\u5148\u540e\u6267\u884c\u7684\u903b\u8f91\u987a\u5e8f\u5173\u9645 2.\u5f02\u6b65:\u4ee3\u7801\u6267\u884c\u6d41\u7a0b\u6ca1\u6709\u4efb\u4f55\u5173\u8054\u6027<\/p>\n<p>\u4fe1\u53f7\u91cf\u5e94\u7528&#xff1a;\u2460\u4fe1\u53f7\u91cf\u53ef\u4ee5\u5b9e\u73b0\u591a\u7ebf\u7a0b\u95f4\u7684\u540c\u6b65&#xff08;\u4fe1\u53f7\u91cf\u662f\u5b9e\u73b0\u540c\u6b65\u7684\u5de5\u5177&#xff09;&#xff0c;\u8ba9\u591a\u4e2a\u4efb\u52a1\u5177\u6709<span style=\"background-color:#f9eda6\">\u5148\u540e\u987a\u5e8f\u5173\u7cfb&#xff08;\u4e0d\u4ec5\u53ef\u4ee5\u9632\u6b62\u8d44\u6e90\u7ade\u4e89&#xff0c;\u8fd8\u80fd\u8ba9\u591a\u4efb\u52a1\u6709\u4e25\u683c\u987a\u5e8f&#xff0c;\u6bd4\u4e92\u65a5\u9501\u66f4\u5f3a\u5927&#xff09;<\/span>\u2461\u5b9e\u73b0\u591a\u529f\u80fd\u7684\u62c6\u5206&#xff0c;\u907f\u514d\u529f\u80fd\u95f4\u8026\u5408&#xff0c;\u4e00\u4e2a\u7ebf\u7a0b\u5b8c\u6210\u4e00\u4e2a\u6982\u5ff5<\/p>\n<p id=\"1.%20%E5%90%8C%E6%AD%A5%E4%B8%8E%E4%BA%92%E6%96%A5%E7%9A%84%E5%85%B3%E7%B3%BB\">\u540c\u6b65\u4e0e\u4e92\u65a5\u7684\u5173\u7cfb:<\/p>\n<p>\u540c\u6b65\u662f\u4e92\u65a5\u7684 \u201c\u7279\u4f8b\u201d&#xff1a;\u540c\u6b65\u4e0d\u4ec5\u8981\u6392\u4ed6\u8bbf\u95ee&#xff0c;\u8fd8\u8981\u63a7\u5236\u6267\u884c\u987a\u5e8f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"227\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226121735-69a039df2939b.png\" width=\"328\" \/><\/p>\n<p>\u4e92\u65a5\u9501\u4e0e\u4fe1\u53f7\u91cf\u7684\u533a\u522b<\/p>\n<ul>\n<li>\u4e92\u65a5\u9501&#xff1a;\u52a0\u9501\u548c\u89e3\u9501\u662f\u540c\u4e00\u4e2a\u7ebf\u7a0b&#xff0c;\u4e34\u754c\u533a\u4ee3\u7801\u77ed\u5c0f\u7cbe\u608d&#xff0c;\u907f\u514d\u4f11\u7720\u3001\u5927\u8017\u65f6\u7684\u64cd\u4f5c<\/li>\n<li>\u4fe1\u53f7\u91cf&#xff1a;th1 \u91ca\u653e th2&#xff0c;th2 \u91ca\u653e th1\u3002\u7531\u7ebf\u7a0b\u4ea4\u53c9\u91ca\u653e\u3002\u53ef\u4ee5\u6709\u9002\u5f53\u4f11\u7720\u3001\u5c0f\u7684\u8017\u65f6\u64cd\u4f5c<\/li>\n<\/ul>\n<h3 id=\"6.2%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9A%84%E5%8E%9F%E7%90%86\">6.2\u4fe1\u53f7\u91cf\u7684\u539f\u7406<\/h3>\n<p>\u4fe1\u53f7\u91cf\u662f\u4e00\u4e2a\u6574\u6570 sem&#xff0c;\u901a\u8fc7 \u7533\u8bf7\u8d44\u6e90 \u548c \u91ca\u653e\u8d44\u6e90 \u5b9e\u73b0\u540c\u6b65&#xff1a;<\/p>\n<ul>\n<li>\u7533\u8bf7\u8d44\u6e90&#xff1a;sem&#8211;&#xff0c;\u82e5 sem&lt;0 \u5219\u7ebf\u7a0b\u963b\u585e&#xff1b;<\/li>\n<li>\u91ca\u653e\u8d44\u6e90&#xff1a;sem&#043;&#043;&#xff0c;\u82e5 sem&lt;&#061;0 \u5219\u5524\u9192\u4e00\u4e2a\u963b\u585e\u7684\u7ebf\u7a0b\u3002<\/li>\n<\/ul>\n<h3 id=\"6.3%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9B%B8%E5%85%B3%E5%87%BD%E6%95%B0%EF%BC%88semaphore.h%E5%BA%93%EF%BC%89\">6.3\u4fe1\u53f7\u91cf\u76f8\u5173\u51fd\u6570&#xff08;semaphore.h\u5e93&#xff09;<\/h3>\n<p>\u76f8\u5173\u51fd\u6570\u3010\u51fd\u6570&#xff1a;\u5c31\u56db\u4e2a\u3011\u3010\u5e94\u7528&#xff1a;\u5c31\u4e00\u4e2a\u2014\u2014\u4f7f\u591a\u4e2a\u4efb\u52a1\u5177\u6709\u5148\u540e\u987a\u5e8f\u5173\u7cfb\u3011<\/p>\n<p>\u521d\u59cb\u5316\u8d44\u6e90 : sem_init\u00a0 \u00a0 \u00a0 \u00a0<\/p>\n<p>\u9500\u6bc1\u8d44\u6e90\u00a0 \u00a0 :\u00a0 sem_destroy \u7533\u8bf7\u8d44\u6e90\u00a0: sem_wait \u91ca\u653e\u8d44\u6e90\u00a0 \u00a0&#xff1a;sem_post\u00a0 \u00a0 \u00a0 \u00a0<\/p>\n<p>sem_init<\/p>\n<p>\u539f\u578b&#xff1a;int sem_init(sem_t *sem, int pshared, unsigned int value); \u529f\u80fd:<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u5bf9\u4fe1\u53f7\u91cf\u521d\u59cb\u5316 \u53c2\u6570:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sem:\u4fe1\u53f7\u91cf\u7a7a\u95f4\u9996\u5730\u5740<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pshared:\u4fe1\u53f7\u91cf\u7684\u4f5c\u7528\u57df\u7ebf\u7a0b\u95f4\u5171\u4eab \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a00\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u7ebf\u7a0b\u95f4\u5171\u4eab \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u975e0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fdb\u7a0b\u95f4\u5171\u4eab \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0value:\u4fe1\u53f7\u91cf\u7684\u521d\u59cb\u503c&#xff08;\u5982 0 \u8868\u793a \u201c\u65e0\u8d44\u6e90\u201d&#xff0c;1 \u8868\u793a \u201c\u6709 1 \u4e2a\u8d44\u6e90\u201d&#xff09;<\/p>\n<p>\u8fd4\u56de\u503c: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6210\u529f\u8fd4\u56de0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5931\u8d25\u8fd4\u56de\u975e0<\/p>\n<p>sem_destory<\/p>\n<p>\u539f\u578b&#xff1a;int sem_destory(sem_t *sem); \u529f\u80fd:<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0\u00a0\u4f7f\u7528\u5b8c\u6bd5\u5c06\u6307\u5b9a\u7684\u4fe1\u53f7\u91cf\u9500\u6bc1\u3002 \u53c2\u6570: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sem:\u4fe1\u53f7\u91cf\u7a7a\u95f4\u9996\u5730\u5740<\/p>\n<p>\u8fd4\u56de\u503c: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6210\u529f\u8fd4\u56de0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5931\u8d25\u8fd4\u56de\u975e0<\/p>\n<p>sem_wait<\/p>\n<p>\u539f\u578b&#xff1a;int sem_wait(sem_t *sem); \u529f\u80fd:<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u7533\u8bf7\u8d44\u6e90&#xff0c;\u8ba9\u8d44\u6e90\u6570-1&#xff0c;\u5982\u679c\u8d44\u6e90\u6570\u4e3a0&#xff0c;\u5219\u963b\u585e\u7b49\u5f85&#xff0c;\u4e00\u65e6\u6709\u8d44\u6e90\u5219\u81ea\u52a8\u7533\u8bf7\u8d44\u6e90\u5e76\u7ee7\u7eed\u8fd0\u884c\u7a0b\u5e8f\u3002 \u53c2\u6570: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sem:\u4fe1\u53f7\u91cf\u7a7a\u95f4\u9996\u5730\u5740<\/p>\n<p>\u8fd4\u56de\u503c: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6210\u529f\u8fd4\u56de0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5931\u8d25\u8fd4\u56de\u975e0<\/p>\n<p>sem_post<\/p>\n<p>\u539f\u578b&#xff1a;int sem_post(sem_t *sem); \u529f\u80fd:<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u91ca\u653e\u8d44\u6e90&#xff0c;\u5c06\u6307\u5b9a\u7684 sem \u4fe1\u53f7\u91cf\u8d44\u6e90\u91ca\u653e&#xff0c;\u8ba9\u8d44\u6e90\u6570&#043;1&#xff08;\u5373\u6267\u884c sem &#061; sem&#043;1&#xff09;&#xff0c;\u7ebf\u7a0b\u5728\u8be5\u51fd\u6570\u4e0a\u4e0d\u4f1a\u963b\u585e\u3002 \u53c2\u6570: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sem:\u4fe1\u53f7\u91cf\u7a7a\u95f4\u9996\u5730\u5740<\/p>\n<p>\u8fd4\u56de\u503c: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6210\u529f\u8fd4\u56de0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5931\u8d25\u8fd4\u56de\u975e0<\/p>\n<h3 id=\"6.4%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9A%84%E4%BD%BF%E7%94%A8%E6%AD%A5%E9%AA%A4\">6.4\u4fe1\u53f7\u91cf\u7684\u4f7f\u7528\u6b65\u9aa4<\/h3>\n<p>\u6b65\u9aa4\u662f&#xff1a;\u5b9a\u4e49\u2192\u521d\u59cb\u5316\u2192PV \u64cd\u4f5c\u2192\u9500\u6bc1\u3002<\/p>\n<h4 id=\"6.4.1%E5%AE%9A%E4%B9%89%E4%BF%A1%E5%8F%B7%E9%87%8F\">6.4.1\u5b9a\u4e49\u4fe1\u53f7\u91cf<\/h4>\n<p>#include &lt;semaphore.h&gt;<br \/>\nsem_t sem_r;<br \/>\nsem_t sem_w; <\/p>\n<h4 id=\"6.4.2%C2%A0%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BF%A1%E5%8F%B7%E9%87%8F\">6.4.2\u00a0\u521d\u59cb\u5316\u4fe1\u53f7\u91cf<\/h4>\n<p>sem_init(&amp;sem_r, 0, 0);<br \/>\nsem_init(&amp;sem_w, 0, 1); <\/p>\n<h4 id=\"6.4.3%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9A%84%E6%93%8D%E4%BD%9C%E2%80%94%E2%80%94%E7%94%B3%E8%AF%B7%E8%B5%84%E6%BA%90\">6.4.3\u4fe1\u53f7\u91cf\u7684\u64cd\u4f5c\u2014\u2014\u7533\u8bf7\u8d44\u6e90<\/h4>\n<p> sem_wait(&amp;sem_w); <\/p>\n<h4 id=\"6.4.4%E4%BF%A1%E5%8F%B7%E9%87%8F%E7%9A%84%E6%93%8D%E4%BD%9C%E2%80%94%E2%80%94%E9%87%8A%E6%94%BE%E8%B5%84%E6%BA%90\">6.4.4\u4fe1\u53f7\u91cf\u7684\u64cd\u4f5c\u2014\u2014\u91ca\u653e\u8d44\u6e90<\/h4>\n<p>sem_post(&amp;sem_r); <\/p>\n<h4 id=\"6.4.5%E9%94%80%E6%AF%81%E4%BF%A1%E5%8F%B7%E9%87%8F\">6.4.5\u9500\u6bc1\u4fe1\u53f7\u91cf<\/h4>\n<p>sem_destroy(&amp;sem_r);<br \/>\nsem_destroy(&amp;sem_w); <\/p>\n<h4 id=\"4.%E4%BF%A1%E5%8F%B7%E9%87%8F%E5%90%8C%E6%AD%A5%E5%AE%9E%E6%88%98%E7%A4%BA%E4%BE%8B\">6.4.6\u4fe1\u53f7\u91cf\u540c\u6b65\u5b9e\u6218\u793a\u4f8b<\/h4>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;  \/\/ \u7528\u4e8e\u7ed9\u6307\u9488\u7f6e\u7a7a<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;pthread.h&gt; \/\/\u7528\u4e8e\u7ebf\u7a0b\u76f8\u5173\u51fd\u6570<br \/>\n#include &lt;semaphore.h&gt; \/\/\u7528\u4e8e\u4fe1\u53f7\u91cf\u76f8\u5173\u51fd\u6570<\/p>\n<p>char tmpbuffer[4096] &#061; {0};<br \/>\nsem_t sem_r; \/\/\u8bfb\u8d44\u6e90<br \/>\nsem_t sem_w; \/\/\u5199\u8d44\u6e90(\u5199\u8fdbtmpbuffer)<\/p>\n<p>void* threadfun1(void* arg) \/\/\u5199<br \/>\n{<br \/>\n    printf(&#034;\u7ebf\u7a0b\u5f00\u59cb\u6267\u884c&#xff08;TID&#xff1a;%#x&#xff09;\\\\n&#034;,(unsigned int)pthread_self());\/\/%#x:\u5341\u516d\u8fdb\u5236\u6570&#xff0c;\u5c0f\u5199\u5b57\u6bcd&#xff0c;\u5e76\u81ea\u52a8\u6dfb\u52a0 0x\u524d\u7f00\u3002<\/p>\n<p>    while(1)  \/\/\u6b7b\u5faa\u73af\u662f\u4e3a\u4e86\u9632\u6b62\u8fdb\u7a0b\u7ed3\u675f&#xff0c;\u56e0\u4e3a\u8fdb\u7a0b\u4e0d\u5728\u7ebf\u7a0b\u4e5f\u4e0d\u5728<br \/>\n    {<br \/>\n        sem_wait(&amp;sem_w);<br \/>\n        gets(tmpbuffer);<br \/>\n        sem_post(&amp;sem_r);<br \/>\n        if(0 &#061;&#061; strcmp(tmpbuffer,&#034;.quit&#034;))<br \/>\n        {<br \/>\n            break;<br \/>\n        }<br \/>\n    }<br \/>\n    return NULL;<br \/>\n}<\/p>\n<p>void* threadfun2(void* arg) \/\/\u8bfb\u51fa\u6765<br \/>\n{<br \/>\n    printf(&#034;\u7ebf\u7a0b\u5f00\u59cb\u6267\u884c&#xff08;TID&#xff1a;%#x&#xff09;\\\\n&#034;,(unsigned int)pthread_self());\/\/%#x:\u5341\u516d\u8fdb\u5236\u6570&#xff0c;\u5c0f\u5199\u5b57\u6bcd&#xff0c;\u5e76\u81ea\u52a8\u6dfb\u52a0 0x\u524d\u7f00\u3002<\/p>\n<p>    while(1)  \/\/\u6b7b\u5faa\u73af\u662f\u4e3a\u4e86\u9632\u6b62\u8fdb\u7a0b\u7ed3\u675f&#xff0c;\u56e0\u4e3a\u8fdb\u7a0b\u4e0d\u5728\u7ebf\u7a0b\u4e5f\u4e0d\u5728<br \/>\n    {<br \/>\n        sem_wait(&amp;sem_r);<br \/>\n        if(0 &#061;&#061; strcmp(tmpbuffer,&#034;.quit&#034;))<br \/>\n        {<br \/>\n            break;<br \/>\n        }<\/p>\n<p>        printf(&#034;tmpbuff &#061; %s\\\\n&#034;,tmpbuffer);<br \/>\n        sem_post(&amp;sem_w);<br \/>\n    }<br \/>\n    return NULL;<br \/>\n}<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n    int ret1 &#061;  0;<br \/>\n    int ret2 &#061;  0;    <\/p>\n<p>    pthread_t tid1;\/\/\u521b\u5efa\u7ebf\u7a0b<br \/>\n    pthread_t tid2;<\/p>\n<p>    sem_init(&amp;sem_r,0,1);<br \/>\n    sem_init(&amp;sem_w,0,0);<\/p>\n<p>    ret1 &#061;pthread_create(&amp;tid1,NULL,threadfun1,NULL);\/\/\u521b\u5efa\u7ebf\u7a0b1<br \/>\n    ret2 &#061;pthread_create(&amp;tid2,NULL,threadfun2,NULL);<br \/>\n#if 1<br \/>\n    if(ret1 !&#061; 0 || ret2 !&#061; 0)<br \/>\n    {<br \/>\n        perror(&#034;fail to pthread_create&#034;);<br \/>\n        return -1;<br \/>\n    }<br \/>\n#endif<br \/>\n    pthread_join(tid1,NULL);\/\/\u963b\u585e\u56de\u6536\u7ebf\u7a0b<br \/>\n    pthread_join(tid2,NULL);<\/p>\n<p>    sem_destroy(&amp;sem_r);\/\/\u4fe1\u53f7\u91cf\u7684\u9500\u6bc1<br \/>\n    sem_destroy(&amp;sem_w);\/\/\u4fe1\u53f7\u91cf\u7684\u9500\u6bc1 <\/p>\n<p>    return 0;<br \/>\n} <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n1.\u91cd\u8981\u6982\u5ff5<br \/>\n2.\u7ebf\u7a0b\u95f4\u901a\u4fe1\u5b9e\u73b0\u65b9\u5f0f\u2014\u2014\u6700\u7b80\u5355\u7684\u65b9\u6cd5:\u5168\u5c40\u53d8\u91cf\u9501&#xff08;\u4e92\u65a5\u9501&#xff09;<br \/>\n3.\u539f\u5b50\u64cd\u4f5c<br \/>\n4.\u4e92\u65a5\u9501&#xff08;Mutex&#xff09;<br \/>\n4.1\u4e92\u65a5\u9501\u76f8\u5173\u6982\u5ff5<br \/>\n4.2\u4e92\u65a5\u9501\u76f8\u5173\u51fd\u6570&#xff08;pthread \u5e93&#xff09;<br \/>\n4.3\u4e92\u65a5\u9501\u4f7f\u7528\u6b65\u9aa4<br \/>\n4.3.1\u5b9a\u4e49\u4e92\u65a5\u9501<br \/>\n4.3.2\u521d\u59cb\u5316\u4e92\u65a5\u9501<br \/>\n4.3.3\u52a0\u9501&#xff08;\u8fdb\u5165\u4e34\u754c\u533a&#xff09;<br \/>\n4.3.4\u89e3\u9501&#xff08;\u79bb\u5f00\u4e34\u754c\u533a&#xff09; <\/p>\n","protected":false},"author":2,"featured_media":78288,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,76,190],"topic":[],"class_list":["post-78289","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-linux","tag-vscode","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux\uff1a\u7ebf\u7a0b\u95f4\u901a\u4fe1 - \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\/78289.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux\uff1a\u7ebf\u7a0b\u95f4\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 1.\u91cd\u8981\u6982\u5ff5 2.\u7ebf\u7a0b\u95f4\u901a\u4fe1\u5b9e\u73b0\u65b9\u5f0f\u2014\u2014\u6700\u7b80\u5355\u7684\u65b9\u6cd5:\u5168\u5c40\u53d8\u91cf\u9501&#xff08;\u4e92\u65a5\u9501&#xff09; 3.\u539f\u5b50\u64cd\u4f5c 4.\u4e92\u65a5\u9501&#xff08;Mutex&#xff09; 4.1\u4e92\u65a5\u9501\u76f8\u5173\u6982\u5ff5 4.2\u4e92\u65a5\u9501\u76f8\u5173\u51fd\u6570&#xff08;pthread \u5e93&#xff09; 4.3\u4e92\u65a5\u9501\u4f7f\u7528\u6b65\u9aa4 4.3.1\u5b9a\u4e49\u4e92\u65a5\u9501 4.3.2\u521d\u59cb\u5316\u4e92\u65a5\u9501 4.3.3\u52a0\u9501&#xff08;\u8fdb\u5165\u4e34\u754c\u533a&#xff09; 4.3.4\u89e3\u9501&#xff08;\u79bb\u5f00\u4e34\u754c\u533a&#xff09;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/78289.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-26T12:17:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226121735-69a039df2939b.png\" \/>\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=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78289.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/78289.html\",\"name\":\"Linux\uff1a\u7ebf\u7a0b\u95f4\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-26T12:17:36+00:00\",\"dateModified\":\"2026-02-26T12:17:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/78289.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/78289.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78289.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux\uff1a\u7ebf\u7a0b\u95f4\u901a\u4fe1\"}]},{\"@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":"Linux\uff1a\u7ebf\u7a0b\u95f4\u901a\u4fe1 - \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\/78289.html","og_locale":"zh_CN","og_type":"article","og_title":"Linux\uff1a\u7ebf\u7a0b\u95f4\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 1.\u91cd\u8981\u6982\u5ff5 2.\u7ebf\u7a0b\u95f4\u901a\u4fe1\u5b9e\u73b0\u65b9\u5f0f\u2014\u2014\u6700\u7b80\u5355\u7684\u65b9\u6cd5:\u5168\u5c40\u53d8\u91cf\u9501&#xff08;\u4e92\u65a5\u9501&#xff09; 3.\u539f\u5b50\u64cd\u4f5c 4.\u4e92\u65a5\u9501&#xff08;Mutex&#xff09; 4.1\u4e92\u65a5\u9501\u76f8\u5173\u6982\u5ff5 4.2\u4e92\u65a5\u9501\u76f8\u5173\u51fd\u6570&#xff08;pthread \u5e93&#xff09; 4.3\u4e92\u65a5\u9501\u4f7f\u7528\u6b65\u9aa4 4.3.1\u5b9a\u4e49\u4e92\u65a5\u9501 4.3.2\u521d\u59cb\u5316\u4e92\u65a5\u9501 4.3.3\u52a0\u9501&#xff08;\u8fdb\u5165\u4e34\u754c\u533a&#xff09; 4.3.4\u89e3\u9501&#xff08;\u79bb\u5f00\u4e34\u754c\u533a&#xff09;","og_url":"https:\/\/www.wsisp.com\/helps\/78289.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-26T12:17:36+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226121735-69a039df2939b.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/78289.html","url":"https:\/\/www.wsisp.com\/helps\/78289.html","name":"Linux\uff1a\u7ebf\u7a0b\u95f4\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-26T12:17:36+00:00","dateModified":"2026-02-26T12:17:36+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/78289.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/78289.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/78289.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Linux\uff1a\u7ebf\u7a0b\u95f4\u901a\u4fe1"}]},{"@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\/78289","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=78289"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/78289\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/78288"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=78289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=78289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=78289"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=78289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}