{"id":94896,"date":"2026-08-15T17:17:33","date_gmt":"2026-08-15T09:17:33","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/94896.html"},"modified":"2026-08-15T17:17:33","modified_gmt":"2026-08-15T09:17:33","slug":"%e3%80%90%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%bb%9f%e3%80%91%e8%af%bb%e5%86%99%e9%94%81%ef%bc%88%e7%bb%83%e4%b9%a0%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/94896.html","title":{"rendered":"\u3010\u64cd\u4f5c\u7cfb\u7edf\u3011\u8bfb\u5199\u9501\uff08\u7ec3\u4e60\uff09"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"136\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260815091732-6a802eac88cbc.png\" width=\"514\" \/><\/p>\n<p>\u8981\u5728 C&#043;&#043; \u4e2d\u4f7f\u7528\u8bfb\u5199\u9501&#xff08;read-write lock&#xff09;\u6765\u6a21\u62df\u94f6\u884c\u8d26\u6237\u7ba1\u7406\u7cfb\u7edf&#xff0c;\u6211\u4eec\u9700\u8981\u4f7f\u7528\u9002\u5f53\u7684\u540c\u6b65\u673a\u5236\u6765\u786e\u4fdd\u591a\u7ebf\u7a0b\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\u65f6\u7684\u5b89\u5168\u6027\u3002C&#043;&#043; \u6807\u51c6\u5e93\u63d0\u4f9b\u4e86 std::shared_mutex \u6765\u5b9e\u73b0\u8bfb\u5199\u9501&#xff0c;\u5b83\u5141\u8bb8\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bfb\u53d6\u5171\u4eab\u8d44\u6e90&#xff0c;\u4f46\u5728\u5199\u5165\u65f6&#xff0c;\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u8bbf\u95ee\u8d44\u6e90\u3002<\/p>\n<h2>\u8bfb\u5199\u9501\u7684\u5de5\u4f5c\u539f\u7406<\/h2>\n<ul>\n<li>\u8bfb\u9501&#xff1a;\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u6301\u6709\u8bfb\u9501\u5e76\u8bbf\u95ee\u8d44\u6e90&#xff0c;\u524d\u63d0\u662f\u6ca1\u6709\u7ebf\u7a0b\u6301\u6709\u5199\u9501\u3002<\/li>\n<li>\u5199\u9501&#xff1a;\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u6301\u6709\u5199\u9501&#xff0c;\u5e76\u4e14\u6301\u6709\u5199\u9501\u7684\u7ebf\u7a0b\u4e0d\u80fd\u4e0e\u5176\u4ed6\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee\u8d44\u6e90\u3002<\/li>\n<\/ul>\n<h2>\u793a\u4f8b&#xff1a;\u4f7f\u7528\u8bfb\u5199\u9501\u6a21\u62df\u94f6\u884c\u8d26\u6237\u7ba1\u7406<\/h2>\n<p>\u6211\u4eec\u5c06\u901a\u8fc7 std::shared_mutex \u6765\u7ba1\u7406\u5bf9\u94f6\u884c\u8d26\u6237\u4f59\u989d&#xff08;balance&#xff09;\u7684\u8bfb\u5199\u8bbf\u95ee\u3002\u6a21\u62df\u7684\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\u4f7f\u7528 std::shared_lock \u8fdb\u884c\u8bfb\u53d6\u64cd\u4f5c&#xff08;\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u8bfb\u53d6\u4f59\u989d&#xff09;\u3002<\/li>\n<li>\u4f7f\u7528 std::unique_lock \u8fdb\u884c\u5199\u64cd\u4f5c&#xff08;\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u4fee\u6539\u4f59\u989d&#xff09;\u3002<\/li>\n<li>\u4f7f\u7528\u591a\u4e2a\u7ebf\u7a0b\u6765\u5e76\u53d1\u5730\u6a21\u62df\u5b58\u6b3e\u3001\u53d6\u6b3e\u7b49\u64cd\u4f5c&#xff0c;\u5e76\u4f7f\u7528\u8bfb\u5199\u9501\u6765\u786e\u4fdd\u540c\u6b65\u3002<\/li>\n<\/ul>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;thread&gt;<br \/>\n#include &lt;shared_mutex&gt;<br \/>\n#include &lt;cstdlib&gt;<br \/>\n#include &lt;ctime&gt;<br \/>\n#include &lt;unistd.h&gt; \/\/ For sleep()<\/p>\n<p>using namespace std;<\/p>\n<p>\/\/ \u5b9a\u4e49\u5171\u4eab\u8d44\u6e90&#xff1a;\u8d26\u6237\u4f59\u989d\u548c\u8bfb\u5199\u9501<br \/>\nint balance &#061; 1000;<br \/>\nstd::shared_mutex balance_mutex;  \/\/ \u8bfb\u5199\u9501<\/p>\n<p>\/\/ \u8bfb\u64cd\u4f5c&#xff1a;\u67e5\u770b\u4f59\u989d<br \/>\nvoid check_balance() {<br \/>\n    std::shared_lock&lt;std::shared_mutex&gt; lock(balance_mutex);  \/\/ \u5171\u4eab\u8bfb\u9501<br \/>\n    cout &lt;&lt; &#034;Current balance: &#034; &lt;&lt; balance &lt;&lt; endl;<br \/>\n}<\/p>\n<p>\/\/ \u5199\u64cd\u4f5c&#xff1a;\u5b58\u6b3e<br \/>\nvoid deposit(int amount) {<br \/>\n    std::unique_lock&lt;std::shared_mutex&gt; lock(balance_mutex);  \/\/ \u72ec\u5360\u5199\u9501<br \/>\n    balance &#043;&#061; amount;<br \/>\n    cout &lt;&lt; &#034;Deposited &#034; &lt;&lt; amount &lt;&lt; &#034;. New balance: &#034; &lt;&lt; balance &lt;&lt; endl;<br \/>\n}<\/p>\n<p>\/\/ \u5199\u64cd\u4f5c&#xff1a;\u53d6\u6b3e<br \/>\nvoid withdraw(int amount) {<br \/>\n    std::unique_lock&lt;std::shared_mutex&gt; lock(balance_mutex);  \/\/ \u72ec\u5360\u5199\u9501<br \/>\n    if (balance &gt;&#061; amount) {<br \/>\n        balance -&#061; amount;<br \/>\n        cout &lt;&lt; &#034;Withdrew &#034; &lt;&lt; amount &lt;&lt; &#034;. New balance: &#034; &lt;&lt; balance &lt;&lt; endl;<br \/>\n    } else {<br \/>\n        cout &lt;&lt; &#034;Insufficient funds for withdrawal of &#034; &lt;&lt; amount &lt;&lt; endl;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u6a21\u62df\u4fee\u6539\u4f59\u989d\u7684\u7ebf\u7a0b<br \/>\nvoid modify_balance(int iteration) {<br \/>\n    srand(time(0) &#043; iteration);  \/\/ \u4e3a\u6bcf\u4e2a\u7ebf\u7a0b\u8bbe\u5b9a\u4e0d\u540c\u7684\u968f\u673a\u79cd\u5b50<\/p>\n<p>    \/\/ \u6a21\u62df\u5b58\u6b3e<br \/>\n    int deposit_amount &#061; rand() % 201 &#8211; 100;  \/\/ \u968f\u673a\u5b58\u6b3e\u6216\u53d6\u6b3e&#xff08;-100 \u5230 100&#xff09;<br \/>\n    if (deposit_amount &gt;&#061; 0) {<br \/>\n        deposit(deposit_amount);<br \/>\n    } else {<br \/>\n        withdraw(-deposit_amount);  \/\/ \u8d1f\u6570\u8868\u793a\u53d6\u6b3e<br \/>\n    }<\/p>\n<p>    \/\/ \u4f11\u77201\u79d2&#xff0c;\u6a21\u62df\u5176\u4ed6\u64cd\u4f5c<br \/>\n    sleep(1);<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    \/\/ \u521b\u5efa\u591a\u4e2a\u7ebf\u7a0b\u6a21\u62df\u94f6\u884c\u8d26\u6237\u7684\u64cd\u4f5c<br \/>\n    thread t1(modify_balance, 1);<br \/>\n    thread t2(modify_balance, 2);<br \/>\n    thread t3(modify_balance, 3);<br \/>\n    thread t4(modify_balance, 4);<br \/>\n    thread t5(modify_balance, 5);<\/p>\n<p>    \/\/ \u540c\u65f6\u67e5\u770b\u4f59\u989d&#xff08;\u6a21\u62df\u591a\u4e2a\u8bfb\u7ebf\u7a0b&#xff09;<br \/>\n    thread reader1(check_balance);<br \/>\n    thread reader2(check_balance);<br \/>\n    thread reader3(check_balance);<\/p>\n<p>    \/\/ \u7b49\u5f85\u6240\u6709\u7ebf\u7a0b\u6267\u884c\u5b8c\u6210<br \/>\n    t1.join();<br \/>\n    t2.join();<br \/>\n    t3.join();<br \/>\n    t4.join();<br \/>\n    t5.join();<br \/>\n    reader1.join();<br \/>\n    reader2.join();<br \/>\n    reader3.join();<\/p>\n<p>    cout &lt;&lt; &#034;Final balance: &#034; &lt;&lt; balance &lt;&lt; endl;<br \/>\n    return 0;<br \/>\n}<\/p>\n<h2>\u4ee3\u7801\u89e3\u91ca&#xff1a;<\/h2>\n<p>1\u3001\u5171\u4eab\u8d44\u6e90<\/p>\n<ul>\n<li>balance\u00a0\u662f\u6211\u4eec\u7528\u6765\u6a21\u62df\u94f6\u884c\u8d26\u6237\u4f59\u989d\u7684\u5171\u4eab\u8d44\u6e90\u3002<\/li>\n<li>balance_mutex\u00a0\u662f\u6211\u4eec\u4f7f\u7528\u7684\u8bfb\u5199\u9501&#xff0c;\u786e\u4fdd\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e2d\u5bf9\u00a0balance\u00a0\u7684\u64cd\u4f5c\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002<\/li>\n<\/ul>\n<p>2\u3001\u64cd\u4f5c<\/p>\n<ul>\n<li>check_balance()&#xff1a;\u4f7f\u7528\u00a0std::shared_lock\u00a0\u6765\u52a0\u8bfb\u9501&#xff08;\u5171\u4eab\u9501&#xff09;\u3002\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u8bfb\u53d6\u4f59\u989d\u3002<\/li>\n<li>deposit()\u00a0\u548c\u00a0withdraw()&#xff1a;\u4f7f\u7528\u00a0std::unique_lock\u00a0\u6765\u52a0\u5199\u9501&#xff08;\u72ec\u5360\u9501&#xff09;\u3002\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u4fee\u6539\u4f59\u989d\u3002<\/li>\n<\/ul>\n<p>3\u3001\u591a\u7ebf\u7a0b<\/p>\n<ul>\n<li>\u6211\u4eec\u542f\u52a8\u591a\u4e2a\u7ebf\u7a0b\u6765\u6a21\u62df\u5bf9\u00a0balance\u00a0\u7684\u4fee\u6539&#xff0c;\u6bcf\u4e2a\u7ebf\u7a0b\u4f1a\u968f\u673a\u5b58\u6b3e\u6216\u53d6\u6b3e\u3002<\/li>\n<li>\u6211\u4eec\u8fd8\u542f\u52a8\u591a\u4e2a\u8bfb\u53d6\u7ebf\u7a0b\u6765\u6a21\u62df\u540c\u65f6\u8bfb\u53d6\u4f59\u989d\u3002<\/li>\n<\/ul>\n<p>4\u3001\u9501\u7684\u4f7f\u7528<\/p>\n<ul>\n<li>\u5728\u8bfb\u53d6\u4f59\u989d\u65f6&#xff0c;\u4f7f\u7528\u00a0std::shared_lock&#xff0c;\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u8bfb\u53d6\u00a0balance\u3002<\/li>\n<li>\u5728\u5b58\u6b3e\u548c\u53d6\u6b3e\u65f6&#xff0c;\u4f7f\u7528\u00a0std::unique_lock&#xff0c;\u786e\u4fdd\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u4fee\u6539\u00a0balance\u3002<\/li>\n<\/ul>\n<p>5\u3001\u6a21\u62df\u5e76\u53d1\u64cd\u4f5c<\/p>\n<ul>\n<li>sleep(1)\u00a0\u7528\u6765\u6a21\u62df\u6bcf\u4e2a\u7ebf\u7a0b\u64cd\u4f5c\u7684\u5ef6\u8fdf&#xff0c;\u7ed9\u5176\u4ed6\u7ebf\u7a0b\u4e00\u4e9b\u673a\u4f1a\u6267\u884c\u3002<\/li>\n<\/ul>\n<h2>\u8fd0\u884c\u6548\u679c&#xff1a;<\/h2>\n<p>\u6bcf\u6b21\u8fd0\u884c\u7a0b\u5e8f\u65f6&#xff0c;\u7a0b\u5e8f\u4f1a\u5e76\u53d1\u6267\u884c\u5b58\u6b3e\u548c\u53d6\u6b3e\u64cd\u4f5c&#xff0c;\u5e76\u4e14\u6709\u591a\u4e2a\u7ebf\u7a0b\u5728\u540c\u65f6\u8bfb\u53d6\u8d26\u6237\u4f59\u989d\u3002\u901a\u8fc7\u8bfb\u5199\u9501&#xff0c;\u786e\u4fdd\u4e86\u6570\u636e\u7684\u6b63\u786e\u6027\u548c\u7ebf\u7a0b\u5b89\u5168\u3002<\/p>\n<p>&#096;&#096;&#096;cpp<br \/>\n#include&lt;stdio.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<br \/>\n#include&lt;string.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;pthread.h&gt;<br \/>\n#include&lt;fcntl.h&gt;<br \/>\n#include&lt;sys\/stat.h&gt;<br \/>\n#include&lt;errno.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<br \/>\n#include&lt;mqueue.h&gt;<br \/>\n#include&lt;time.h&gt;<\/p>\n<p>int balance &#061; 1000;<br \/>\npthread_rwlock_t rwlock;<\/p>\n<p>void *select_balance(void *arg) {<br \/>\n    pthread_rwlock_rdlock(&amp;rwlock);<br \/>\n    sleep(rand() % 3 &#043; 1);<br \/>\n    printf(&#034;balance: %d\\\\n&#034;, balance);<br \/>\n    pthread_rwlock_unlock(&amp;rwlock);<br \/>\n    return NULL;<br \/>\n}<\/p>\n<p>void *modify_balance(void *arg) {<br \/>\n    pthread_rwlock_wrlock(&amp;rwlock);<br \/>\n    sleep(1);<br \/>\n    balance &#043;&#061; atoi((char *)arg);<br \/>\n    printf(&#034;modify: %d, balance: %d\\\\n&#034;, atoi((char *)arg), balance);<br \/>\n    pthread_rwlock_unlock(&amp;rwlock);<br \/>\n    return NULL;<br \/>\n}<\/p>\n<p>int main(int argc, char *argv[])<br \/>\n{<br \/>\n    if (argc !&#061; 6) {<br \/>\n        printf(&#034;\u53c2\u6570\u6570\u91cf\u9519\u8bef&#xff0c;\u6b63\u786e\u53c2\u6570\u6570\u91cf\u5e94\u4e3a5\u4e2a&#xff01;\\\\n&#034;);<br \/>\n        return -1;<br \/>\n    }<br \/>\n    pthread_rwlock_init(&amp;rwlock, NULL);<br \/>\n    srand(time(NULL));<br \/>\n    pthread_t tid[15];<br \/>\n    for (int i &#061; 0; i &lt; 5; i&#043;&#043;) {<br \/>\n        pthread_create(&amp;tid[i], NULL, modify_balance, argv[i &#043; 1]);<br \/>\n    }<br \/>\n    for (int i &#061; 5; i &lt; 15; i&#043;&#043;) {<br \/>\n        pthread_create(&amp;tid[i], NULL, select_balance, NULL);<br \/>\n    }<br \/>\n    for (int i &#061; 0; i &lt; 15; i&#043;&#043;) {<br \/>\n        pthread_join(tid[i], NULL);<br \/>\n    }<br \/>\n    pthread_rwlock_destroy(&amp;rwlock);<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u5728 C \u4e2d\u4f7f\u7528\u8bfb\u5199\u9501&#xff08;read-write lock&#xff09;\u6765\u6a21\u62df\u94f6\u884c\u8d26\u6237\u7ba1\u7406\u7cfb\u7edf&#xff0c;\u6211\u4eec\u9700\u8981\u4f7f\u7528\u9002\u5f53\u7684\u540c\u6b65\u673a\u5236\u6765\u786e\u4fdd\u591a\u7ebf\u7a0b\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\u65f6\u7684\u5b89\u5168\u6027\u3002C \u6807\u51c6\u5e93\u63d0\u4f9b\u4e86 std::shared_mutex \u6765\u5b9e\u73b0\u8bfb\u5199\u9501&#xff0c;\u5b83\u5141\u8bb8\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bfb\u53d6\u5171\u4eab\u8d44\u6e90&#xff0c;\u4f46\u5728\u5199\u5165\u65f6&#xff0c;\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u8bbf\u95ee\u8d44\u6e90\u3002\u8bfb\u5199\u9501\u7684\u5de5\u4f5c\u539f\u7406\u8bfb\u9501&#xff1a;\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u6301\u6709\u8bfb\u9501\u5e76\u8bbf\u95ee\u8d44\u6e90&#xff0c;\u524d\u63d0\u662f\u6ca1\u6709\u7ebf\u7a0b\u6301\u6709\u5199\u9501\u3002\u5199\u9501&amp;<\/p>\n","protected":false},"author":2,"featured_media":94895,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10187,10876,426,16],"topic":[],"class_list":["post-94896","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-codingplan","tag-10876","tag-jvm","tag-16"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u64cd\u4f5c\u7cfb\u7edf\u3011\u8bfb\u5199\u9501\uff08\u7ec3\u4e60\uff09 - \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\/94896.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u64cd\u4f5c\u7cfb\u7edf\u3011\u8bfb\u5199\u9501\uff08\u7ec3\u4e60\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u8981\u5728 C \u4e2d\u4f7f\u7528\u8bfb\u5199\u9501&#xff08;read-write lock&#xff09;\u6765\u6a21\u62df\u94f6\u884c\u8d26\u6237\u7ba1\u7406\u7cfb\u7edf&#xff0c;\u6211\u4eec\u9700\u8981\u4f7f\u7528\u9002\u5f53\u7684\u540c\u6b65\u673a\u5236\u6765\u786e\u4fdd\u591a\u7ebf\u7a0b\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\u65f6\u7684\u5b89\u5168\u6027\u3002C \u6807\u51c6\u5e93\u63d0\u4f9b\u4e86 std::shared_mutex \u6765\u5b9e\u73b0\u8bfb\u5199\u9501&#xff0c;\u5b83\u5141\u8bb8\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bfb\u53d6\u5171\u4eab\u8d44\u6e90&#xff0c;\u4f46\u5728\u5199\u5165\u65f6&#xff0c;\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u8bbf\u95ee\u8d44\u6e90\u3002\u8bfb\u5199\u9501\u7684\u5de5\u4f5c\u539f\u7406\u8bfb\u9501&#xff1a;\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u6301\u6709\u8bfb\u9501\u5e76\u8bbf\u95ee\u8d44\u6e90&#xff0c;\u524d\u63d0\u662f\u6ca1\u6709\u7ebf\u7a0b\u6301\u6709\u5199\u9501\u3002\u5199\u9501&amp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/94896.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-15T09:17:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260815091732-6a802eac88cbc.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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/94896.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/94896.html\",\"name\":\"\u3010\u64cd\u4f5c\u7cfb\u7edf\u3011\u8bfb\u5199\u9501\uff08\u7ec3\u4e60\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-15T09:17:33+00:00\",\"dateModified\":\"2026-08-15T09:17:33+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/94896.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/94896.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/94896.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u64cd\u4f5c\u7cfb\u7edf\u3011\u8bfb\u5199\u9501\uff08\u7ec3\u4e60\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010\u64cd\u4f5c\u7cfb\u7edf\u3011\u8bfb\u5199\u9501\uff08\u7ec3\u4e60\uff09 - \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\/94896.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u64cd\u4f5c\u7cfb\u7edf\u3011\u8bfb\u5199\u9501\uff08\u7ec3\u4e60\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u8981\u5728 C \u4e2d\u4f7f\u7528\u8bfb\u5199\u9501&#xff08;read-write lock&#xff09;\u6765\u6a21\u62df\u94f6\u884c\u8d26\u6237\u7ba1\u7406\u7cfb\u7edf&#xff0c;\u6211\u4eec\u9700\u8981\u4f7f\u7528\u9002\u5f53\u7684\u540c\u6b65\u673a\u5236\u6765\u786e\u4fdd\u591a\u7ebf\u7a0b\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\u65f6\u7684\u5b89\u5168\u6027\u3002C \u6807\u51c6\u5e93\u63d0\u4f9b\u4e86 std::shared_mutex \u6765\u5b9e\u73b0\u8bfb\u5199\u9501&#xff0c;\u5b83\u5141\u8bb8\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bfb\u53d6\u5171\u4eab\u8d44\u6e90&#xff0c;\u4f46\u5728\u5199\u5165\u65f6&#xff0c;\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u8bbf\u95ee\u8d44\u6e90\u3002\u8bfb\u5199\u9501\u7684\u5de5\u4f5c\u539f\u7406\u8bfb\u9501&#xff1a;\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u6301\u6709\u8bfb\u9501\u5e76\u8bbf\u95ee\u8d44\u6e90&#xff0c;\u524d\u63d0\u662f\u6ca1\u6709\u7ebf\u7a0b\u6301\u6709\u5199\u9501\u3002\u5199\u9501&amp;","og_url":"https:\/\/www.wsisp.com\/helps\/94896.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-15T09:17:33+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260815091732-6a802eac88cbc.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/94896.html","url":"https:\/\/www.wsisp.com\/helps\/94896.html","name":"\u3010\u64cd\u4f5c\u7cfb\u7edf\u3011\u8bfb\u5199\u9501\uff08\u7ec3\u4e60\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-15T09:17:33+00:00","dateModified":"2026-08-15T09:17:33+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/94896.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/94896.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/94896.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u64cd\u4f5c\u7cfb\u7edf\u3011\u8bfb\u5199\u9501\uff08\u7ec3\u4e60\uff09"}]},{"@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\/94896","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=94896"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/94896\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/94895"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=94896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=94896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=94896"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=94896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}