{"id":113439,"date":"2026-10-06T11:41:03","date_gmt":"2026-10-06T03:41:03","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/113439.html"},"modified":"2026-10-06T11:41:03","modified_gmt":"2026-10-06T03:41:03","slug":"%e3%80%90%e4%bb%93%e9%a2%89%e8%af%ad%e8%a8%80%e5%85%a5%e9%97%a8-%c2%b7-%e7%ac%ac27%e8%af%be%e3%80%91","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/113439.html","title":{"rendered":"\u3010\u4ed3\u9889\u8bed\u8a00\u5165\u95e8 \u00b7 \u7b2c27\u8bfe\u3011"},"content":{"rendered":"<h2>\u7b2c 27 \u8bfe \u7ebf\u7a0b\u540c\u6b65&#xff1a;\u4e92\u65a5\u9501\u3001\u539f\u5b50\u7c7b\u578b\u4e0e\u6761\u4ef6\u53d8\u91cf<\/h2>\n<p>\u4e0a\u8282\u8bfe\u7ed3\u5c3e\u7684 CounterBox \u60e8\u6848\u8fd8\u60ac\u7740&#xff1a;10 \u4e2a\u7ebf\u7a0b\u5404\u52a0 10000 \u6b21&#xff0c;\u671f\u671b 100000&#xff0c;\u5b9e\u9645\u53ea\u6709 33017\u300133874\u2026\u2026\u6bcf\u6b21\u8dd1\u6570\u5b57\u8fd8\u90fd\u4e0d\u4e00\u6837\u3002\u672c\u8bfe\u5c31\u6765\u7b97\u8d26&#xff1a;\u7528 Mutex \u4e92\u65a5\u9501\u628a&#034;\u8bfb\u2014\u52a0\u2014\u5199&#034;\u4e09\u6b65\u5408\u6210\u4e00\u6b65&#xff0c;\u7528 Atomic \u539f\u5b50\u7c7b\u578b\u8ba9\u81ea\u589e\u672c\u8eab\u4e0d\u53ef\u5206\u5272&#xff0c;\u518d\u7528 Condition \u6761\u4ef6\u53d8\u91cf\u89e3\u51b3&#034;\u7ebf\u7a0b\u4e4b\u95f4\u4f60\u7b49\u6211\u3001\u6211\u7b49\u4f60&#034;\u7684\u901a\u4fe1\u95ee\u9898\u3002<\/p>\n<p>\u53e6\u5916&#xff0c;\u672c\u8bfe\u4f1a\u5148\u5b9e\u6d4b\u4e00\u4e2a\u4e0a\u8282\u8bfe\u9884\u544a\u91cc\u63d0\u5230\u3001\u5f88\u591a\u8d44\u6599\u4e5f\u5728\u8bb2\u7684\u4e1c\u897f\u2014\u2014Channel \u901a\u9053&#xff0c;\u5e76\u5982\u5b9e\u544a\u8bc9\u4f60\u4ed3\u9889 SDK 1.2.0 \u7684\u73b0\u72b6&#xff0c;\u7136\u540e\u7528\u672c\u8bfe\u5b66\u7684\u539f\u8bed\u4eb2\u624b\u5b9e\u73b0\u4e00\u4e2a\u963b\u585e\u961f\u5217&#xff08;\u901a\u9053\u6700\u6838\u5fc3\u7684\u90e8\u5206&#xff09;\u3002<\/p>\n<p>\u672c\u6587\u6240\u6709\u4ee3\u7801\u4e0e\u8f93\u51fa\u5747\u5728\u4ed3\u9889 SDK 1.2.0 \u4e0b\u9010\u884c\u5b9e\u6d4b\u7f16\u8bd1\u8fd0\u884c\u3002<\/p>\n<hr \/>\n<h3>\u76ee\u5f55&#xff08;\u7cfb\u5217\u5bfc\u822a&#xff09;<\/h3>\n<p>\u6574\u5957\u8def\u7ebf\u5171 7 \u4e2a\u6a21\u5757\u300130 \u8bfe&#xff1a;<\/p>\n<table>\n<tr>\u6a21\u5757\u8bfe\u6b21\u5185\u5bb9<\/tr>\n<tbody>\n<tr>\n<td>\u4e00\u3001\u73af\u5883\u4e0e\u5165\u95e8<\/td>\n<td>01&#xff5e;05<\/td>\n<td>\u73af\u5883\u642d\u5efa\u4e0e Hello World\u3001\u53d8\u91cf\u4e0e\u57fa\u672c\u7c7b\u578b\u3001\u8fd0\u7b97\u7b26\u4e0e\u8f93\u5165\u8f93\u51fa\u3001\u5206\u652f\u3001\u5faa\u73af<\/td>\n<\/tr>\n<tr>\n<td>\u4e8c\u3001\u5e38\u7528\u7c7b\u578b\u4e0e\u6570\u636e\u7ec4\u7ec7<\/td>\n<td>06&#xff5e;10<\/td>\n<td>\u5b57\u7b26\u4e32\u3001\u6570\u7ec4\u4e0e\u533a\u95f4\u3001ArrayList\/HashMap\/HashSet\u3001\u53ef\u7a7a\u7c7b\u578b\u3001\u9519\u8bef\u5904\u7406<\/td>\n<\/tr>\n<tr>\n<td>\u4e09\u3001\u51fd\u6570\u4e0e\u51fd\u6570\u5f0f<\/td>\n<td>11&#xff5e;14<\/td>\n<td>\u51fd\u6570\u3001Lambda \u4e0e\u9ad8\u9636\u51fd\u6570\u3001\u95ed\u5305\u3001\u8fed\u4ee3\u5668\u4e0e\u60f0\u6027\u5e8f\u5217<\/td>\n<\/tr>\n<tr>\n<td>\u56db\u3001\u9762\u5411\u5bf9\u8c61\u4e0e\u7c7b\u578b\u7cfb\u7edf<\/td>\n<td>15&#xff5e;20<\/td>\n<td>struct\/class\u3001\u6784\u9020\u4e0e\u5c5e\u6027\u3001\u63a5\u53e3\u3001\u679a\u4e3e\u4e0e match \u6a21\u5f0f\u5339\u914d\u3001\u6cdb\u578b\u3001\u6269\u5c55<\/td>\n<\/tr>\n<tr>\n<td>\u4e94\u3001\u5de5\u7a0b\u5316\u4e0e\u6807\u51c6\u5e93<\/td>\n<td>21&#xff5e;25<\/td>\n<td>cjpm \u5305\u7ba1\u7406\u4e0e\u591a\u6587\u4ef6\u3001\u6587\u4ef6 IO\u3001JSON \u5904\u7406\u3001\u7f51\u7edc\u7f16\u7a0b\u3001\u5355\u5143\u6d4b\u8bd5<\/td>\n<\/tr>\n<tr>\n<td>\u516d\u3001\u5e76\u53d1\u7f16\u7a0b<\/td>\n<td>26&#xff5e;28<\/td>\n<td>\u7ebf\u7a0b\u7684\u521b\u5efa\u4e0e\u7b49\u5f85\u3001\u7ebf\u7a0b\u540c\u6b65&#xff08;\u672c\u6587&#xff09;\u3001\u5e76\u53d1\u5b9e\u6218<\/td>\n<\/tr>\n<tr>\n<td>\u4e03\u3001\u9879\u76ee\u5b9e\u6218<\/td>\n<td>29&#xff5e;30<\/td>\n<td>\u547d\u4ee4\u884c\u5c0f\u5de5\u5177\u3001GeoJSON \u6570\u636e\u5904\u7406\u5b9e\u6218<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<li>\u73af\u5883\u642d\u5efa\u4e0e\u7b2c\u4e00\u4e2a\u4ed3\u9889\u7a0b\u5e8f<\/li>\n<li>\u53d8\u91cf\u3001\u5e38\u91cf\u4e0e\u57fa\u672c\u6570\u636e\u7c7b\u578b<\/li>\n<li>\u8fd0\u7b97\u7b26\u4e0e\u6807\u51c6\u8f93\u5165\u8f93\u51fa<\/li>\n<li>\u5206\u652f\u7ed3\u6784\u4e0e match \u8868\u8fbe\u5f0f<\/li>\n<li>\u5faa\u73af\u7ed3\u6784&#xff1a;while \/ for \/ Range<\/li>\n<li>\u5b57\u7b26\u4e32\u8be6\u89e3\u4e0e\u5b57\u7b26\u4e32\u63d2\u503c<\/li>\n<li>\u6570\u7ec4 Array \u4e0e\u533a\u95f4 Range<\/li>\n<li>\u96c6\u5408\u6846\u67b6&#xff1a;ArrayList\u3001HashMap\u3001HashSet<\/li>\n<li>\u53ef\u7a7a\u7c7b\u578b ? \u4e0e Option<\/li>\n<li>\u9519\u8bef\u5904\u7406&#xff1a;\u5f02\u5e38\u673a\u5236\u4e0e Result<\/li>\n<li>\u51fd\u6570\u5b9a\u4e49\u3001\u53c2\u6570\u4e0e\u8fd4\u56de\u503c<\/li>\n<li>Lambda \u4e0e\u9ad8\u9636\u51fd\u6570<\/li>\n<li>\u95ed\u5305\u3001\u4f5c\u7528\u57df\u4e0e\u51fd\u6570\u7c7b\u578b<\/li>\n<li>\u8fed\u4ee3\u5668 Iterator \u4e0e Sequence<\/li>\n<li>\u7ed3\u6784\u4f53 struct \u4e0e\u7c7b class<\/li>\n<li>\u6784\u9020\u51fd\u6570\u3001\u5c5e\u6027\u4e0e\u65b9\u6cd5<\/li>\n<li>\u63a5\u53e3 interface \u4e0e\u5b9e\u73b0<\/li>\n<li>\u679a\u4e3e enum\u3001\u4ee3\u6570\u6570\u636e\u7c7b\u578b\u4e0e match \u6a21\u5f0f\u5339\u914d<\/li>\n<li>\u6cdb\u578b\u7f16\u7a0b<\/li>\n<li>\u6269\u5c55\u3001\u7c7b\u578b\u522b\u540d\u4e0e\u53ef\u89c1\u6027\u63a7\u5236<\/li>\n<li>cjpm \u5305\u7ba1\u7406\u4e0e\u591a\u6587\u4ef6\u9879\u76ee\u7ec4\u7ec7<\/li>\n<li>\u6587\u4ef6\u4e0e\u76ee\u5f55 IO<\/li>\n<li>JSON \u5904\u7406<\/li>\n<li>\u7f51\u7edc\u7f16\u7a0b\u5165\u95e8<\/li>\n<li>\u5355\u5143\u6d4b\u8bd5<\/li>\n<li>\u5e76\u53d1\u57fa\u7840&#xff1a;\u7ebf\u7a0b\u7684\u521b\u5efa\u4e0e\u7b49\u5f85<\/li>\n<li>\u7ebf\u7a0b\u540c\u6b65&#xff1a;\u4e92\u65a5\u9501\u3001\u539f\u5b50\u7c7b\u578b\u4e0e\u6761\u4ef6\u53d8\u91cf&#xff08;\u672c\u6587&#xff09;<\/li>\n<li>\u5e76\u53d1\u5b9e\u6218&#xff1a;\u591a\u7ebf\u7a0b\u4efb\u52a1\u5904\u7406<\/li>\n<li>\u5b9e\u6218\u4e00&#xff1a;\u5e26\u6587\u4ef6\u6301\u4e45\u5316\u7684\u547d\u4ee4\u884c\u5c0f\u5de5\u5177<\/li>\n<li>\u5b9e\u6218\u4e8c&#xff1a;GeoJSON \u6570\u636e\u5904\u7406\u7a0b\u5e8f<\/li>\n<hr \/>\n<h3>\u4e00\u3001\u5148\u7834\u6848&#xff1a;100000 \u662f\u600e\u4e48\u4e22\u7684<\/h3>\n<p>\u5148\u56de\u987e\u4e0a\u8282\u8bfe\u7684&#034;\u7f6a\u72af\u4ee3\u7801&#034;&#xff1a;<\/p>\n<p>class CounterBox {<br \/>\n    var count: Int64 &#061; 0<br \/>\n}<\/p>\n<p>\/\/ 10 \u4e2a\u7ebf\u7a0b&#xff0c;\u6bcf\u4e2a\u628a box.count &#043;&#061; 1 \u6267\u884c 10000 \u6b21<\/p>\n<p>count &#043;&#061; 1 \u770b\u8d77\u6765\u662f&#034;\u4e00\u53e5\u8bdd&#034;&#xff0c;\u4f46\u5bf9 CPU \u6765\u8bf4\u662f\u4e09\u6761\u6307\u4ee4&#xff1a;<\/p>\n<li>\u8bfb&#xff1a;\u628a\u5185\u5b58\u91cc count \u7684\u5f53\u524d\u503c\u8bfb\u5230\u5bc4\u5b58\u5668&#xff1b;<\/li>\n<li>\u6539&#xff1a;\u5bc4\u5b58\u5668\u91cc\u7684\u503c\u52a0 1&#xff1b;<\/li>\n<li>\u5199&#xff1a;\u628a\u65b0\u503c\u5199\u56de\u5185\u5b58\u3002<\/li>\n<p>\u4e24\u4e2a\u7ebf\u7a0b\u53ef\u80fd\u540c\u65f6\u8bfb\u5230\u540c\u4e00\u4e2a\u65e7\u503c&#xff1a;<\/p>\n<p>\u7ebf\u7a0b A&#xff1a;\u8bfb 100 \u2500\u2500\u2192 \u52a0\u5230 101 \u2500\u2500\u2192 \u5199\u56de 101<br \/>\n\u7ebf\u7a0b B&#xff1a;   \u8bfb 100 \u2500\u2500\u2192 \u52a0\u5230 101 \u2500\u2500\u2192 \u5199\u56de 101<\/p>\n<p>\u4e24\u6b21\u52a0\u6cd5&#xff0c;\u7ed3\u679c\u53ea\u6da8\u4e86 1\u2014\u2014\u53e6\u4e00\u6b21\u51ed\u7a7a\u4e22\u4e86\u300210 \u4e2a\u7ebf\u7a0b\u62a2\u5f97\u8d8a\u51f6&#xff0c;\u4e22\u5f97\u8d8a\u591a\u3002<\/p>\n<p>\u7834\u6848\u7ed3\u8bba&#xff1a;\u53ea\u8981\u4e00\u4e2a\u64cd\u4f5c\u4e2d\u95f4\u80fd\u88ab\u522b\u7684\u7ebf\u7a0b\u63d2\u8fdb\u6765&#xff0c;\u5b83\u5c31\u662f\u4e0d\u5b89\u5168\u7684\u3002\u89e3\u6cd5\u4e5f\u5f88\u76f4\u63a5\u2014\u2014\u60f3\u529e\u6cd5\u628a\u8fd9\u4e09\u6b65&#034;\u9501&#034;\u5728\u4e00\u8d77&#xff0c;\u8ba9\u540c\u4e00\u65f6\u523b\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u52a8 count\u3002\u8fd9\u5c31\u662f\u540c\u6b65\u539f\u8bed\u5e72\u7684\u4e8b\u3002<\/p>\n<p>&#x1f4cc; \u672c\u8bfe\u6240\u6709\u7c7b\u578b\u90fd\u5728 std.sync \u5305\u91cc&#xff08;sync &#061; synchronization&#xff0c;\u540c\u6b65&#xff09;&#xff0c;\u7528\u5230\u65f6\u6587\u4ef6\u5f00\u5934\u5199 import std.sync.*\u3002spawn\u3001Future\u3001get()\u3001sleep\u3001Duration \u4ecd\u5728 std.core&#xff0c;\u4e0d\u7528 import\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001Mutex \u4e92\u65a5\u9501&#xff1a;lock \/ unlock \u4e0e synchronized \u5757<\/h3>\n<p>Mutex&#xff08;mutual exclusion \u7684\u7f29\u5199&#xff0c;\u8bfb\u4f5c&#034;\u7f2a\u6cf0\u514b\u65af&#034;&#xff09;\u5c31\u662f\u4e00\u628a\u9501\u3002\u6700\u6734\u7d20\u7684\u7528\u6cd5\u662f\u624b\u52a8 lock() \/ unlock()&#xff1a;<\/p>\n<p>import std.sync.*<\/p>\n<p>main(): Int64 {<br \/>\n    let lock &#061; Mutex()<br \/>\n    lock.lock()<br \/>\n    println(&#034;\u6211\u62ff\u5230\u9501\u4e86&#034;)<br \/>\n    lock.unlock()<\/p>\n<p>    if (lock.tryLock()) {<br \/>\n        println(&#034;\u8fd9\u6b21\u4e5f\u62ff\u5230\u4e86&#034;)<br \/>\n        lock.unlock()<br \/>\n    } else {<br \/>\n        println(&#034;\u9501\u88ab\u5360\u7740&#xff0c;\u6ca1\u62ff\u5230&#034;)<br \/>\n    }<br \/>\n    return 0<br \/>\n}<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>\u6211\u62ff\u5230\u9501\u4e86<br \/>\n\u8fd9\u6b21\u4e5f\u62ff\u5230\u4e86<\/p>\n<p>\u89c4\u5219\u5f88\u7b80\u5355&#xff1a;<\/p>\n<ul>\n<li>lock()&#xff1a;\u62ff\u9501\u3002\u9501\u5982\u679c\u6b63\u88ab\u522b\u7684\u7ebf\u7a0b\u62ff\u7740&#xff0c;\u6211\u5c31\u7ad9\u5728\u95e8\u53e3\u7b49&#xff08;\u963b\u585e&#xff09;&#xff0c;\u76f4\u5230\u62ff\u5230\u4e3a\u6b62&#xff1b;<\/li>\n<li>unlock()&#xff1a;\u653e\u9501&#xff0c;\u8ba9\u7ed9\u522b\u4eba&#xff1b;<\/li>\n<li>tryLock()&#xff1a;\u8bd5\u4e00\u4e0b&#xff0c;\u62ff\u5230\u8fd4\u56de true&#xff0c;\u62ff\u4e0d\u5230\u4e0d\u7b49\u3001\u7acb\u523b\u8fd4\u56de false\u3002\u9002\u5408&#034;\u62ff\u4e0d\u5230\u5c31\u7b97\u4e86&#034;\u7684\u573a\u666f\u3002<\/li>\n<\/ul>\n<p>\u4f46\u624b\u52a8\u914d\u5bf9\u5bb9\u6613\u51fa\u9519\u2014\u2014\u52a0\u4e86\u9501\u5fd8\u4e86\u89e3&#xff0c;\u5176\u4ed6\u7ebf\u7a0b\u5c31\u5f97\u6c38\u8fdc\u6392\u961f\u3002\u4ed3\u9889\u63d0\u4f9b\u4e86\u66f4\u7701\u5fc3\u7684 synchronized \u5757&#xff1a;<\/p>\n<p>import std.sync.*<\/p>\n<p>main(): Int64 {<br \/>\n    let lock &#061; Mutex()<br \/>\n    var count &#061; 0<br \/>\n    synchronized (lock) {<br \/>\n        count &#043;&#061; 1                 \/\/ \u8fd9\u6bb5\u4ee3\u7801\u540c\u4e00\u65f6\u523b\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u6267\u884c<br \/>\n    }<br \/>\n    println(&#034;count &#061; ${count}&#034;)<br \/>\n    return 0<br \/>\n}<\/p>\n<p>count &#061; 1<\/p>\n<p>synchronized (lock) { &#8230; } \u7684\u610f\u601d\u662f&#xff1a;\u201c\u6267\u884c\u82b1\u62ec\u53f7\u91cc\u7684\u4ee3\u7801\u524d\u5148\u62ff\u9501&#xff0c;\u82b1\u62ec\u53f7\u7ed3\u675f\u65f6\u81ea\u52a8\u653e\u9501\u201d\u3002<\/p>\n<p>\u81ea\u52a8\u5230\u4ec0\u4e48\u7a0b\u5ea6&#xff1f;\u91cc\u9762\u629b\u5f02\u5e38&#xff0c;\u9501\u4e5f\u7167\u653e\u4e0d\u8bef&#xff1a;<\/p>\n<p>import std.sync.*<\/p>\n<p>main(): Int64 {<br \/>\n    let lock &#061; Mutex()<br \/>\n    try {<br \/>\n        synchronized (lock) {<br \/>\n            throw IllegalArgumentException(&#034;\u6545\u610f\u6363\u4e71&#034;)<br \/>\n        }<br \/>\n    } catch (e: IllegalArgumentException) {<br \/>\n        println(&#034;\u6355\u83b7\u5f02\u5e38&#xff1a;${e.message}&#034;)<br \/>\n    }<br \/>\n    lock.lock()<br \/>\n    println(&#034;\u9501\u8fd8\u80fd\u62ff\u5230&#xff1a;synchronized \u5df2\u81ea\u52a8\u91ca\u653e&#034;)<br \/>\n    lock.unlock()<br \/>\n    return 0<br \/>\n}<\/p>\n<p>\u6355\u83b7\u5f02\u5e38&#xff1a;\u6545\u610f\u6363\u4e71<br \/>\n\u9501\u8fd8\u80fd\u62ff\u5230&#xff1a;synchronized \u5df2\u81ea\u52a8\u91ca\u653e<\/p>\n<p>&#x1f4cc; \u7ed3\u8bba&#xff1a;99% \u7684\u573a\u666f\u90fd\u7528 synchronized&#xff0c;\u4e0d\u8981\u624b\u5199 lock\/unlock\u3002 \u672c\u8bfe\u540e\u9762\u53ea\u6709&#034;\u521b\u5efa\u6761\u4ef6\u53d8\u91cf&#034;\u90a3\u4e00\u5904\u5fc5\u987b\u624b\u52a8\u52a0\u9501&#xff08;\u7b2c\u516d\u8282\u4f1a\u8bb2\u539f\u56e0&#xff09;\u3002<\/p>\n<p>&#x1f538; \u7248\u672c\u5c0f\u63d0\u793a&#xff1a;SDK 1.2.0 \u7684 Mutex \u672c\u8eab\u5c31\u662f\u53ef\u91cd\u5165\u7684\u2014\u2014\u540c\u4e00\u4e2a\u7ebf\u7a0b\u5bf9\u540c\u4e00\u628a\u9501\u8fde\u7eed lock() \u4e24\u6b21\u4e0d\u4f1a\u6b7b\u9501&#xff0c;\u89e3\u4e24\u6b21\u5373\u53ef\u3002\u65e7\u8d44\u6599\u91cc\u7684 ReentrantMutex \u5df2\u5e9f\u5f03&#xff0c;\u7f16\u8bd1\u4f1a\u544a\u8b66&#xff1a;warning: class &#039;ReentrantMutex&#039; is deprecated. Use &#039;public class Mutex&#039; instead.&#xff0c;\u770b\u5230\u5b83\u76f4\u63a5\u6362\u6210 Mutex \u5373\u53ef\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u4fee\u590d CounterBox&#xff08;\u65b9\u6848\u4e00&#xff1a;synchronized&#xff09;<\/h3>\n<p>\u628a\u4e0a\u8282\u8bfe\u7684 CounterBox \u6539\u9020\u4e00\u4e0b&#xff1a;\u7ed9\u5b83\u914d\u4e00\u628a\u9501&#xff0c;\u6240\u6709\u5bf9 count \u7684\u4fee\u6539\u90fd\u5fc5\u987b\u7a7f\u8fc7\u8fd9\u628a\u9501&#xff1a;<\/p>\n<p>import std.sync.*<br \/>\nimport std.collection.ArrayList<\/p>\n<p>class SafeCounter {<br \/>\n    let lock &#061; Mutex()<br \/>\n    var count: Int64 &#061; 0<\/p>\n<p>    func addOne() {<br \/>\n        synchronized (lock) {<br \/>\n            count &#043;&#061; 1<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>main(): Int64 {<br \/>\n    let box &#061; SafeCounter()<br \/>\n    let futures &#061; ArrayList&lt;Future&lt;Unit&gt;&gt;()<br \/>\n    for (_ in 1..&#061;10) {<br \/>\n        futures.add(spawn {<br \/>\n            for (_ in 1..&#061;10000) {<br \/>\n                box.addOne()<br \/>\n            }<br \/>\n        })<br \/>\n    }<br \/>\n    for (f in futures) {<br \/>\n        f.get()<br \/>\n    }<br \/>\n    println(&#034;\u671f\u671b 100000&#xff0c;\u5b9e\u9645 ${box.count}&#034;)<br \/>\n    return 0<br \/>\n}<\/p>\n<p>\u8fde\u8dd1\u4e09\u6b21&#xff1a;<\/p>\n<p>\u671f\u671b 100000&#xff0c;\u5b9e\u9645 100000<\/p>\n<p>\u671f\u671b 100000&#xff0c;\u5b9e\u9645 100000<\/p>\n<p>\u671f\u671b 100000&#xff0c;\u5b9e\u9645 100000<\/p>\n<p>\u4e09\u6b21\u90fd\u662f 100000\u3002\u539f\u6765\u7684&#034;\u8bfb\u2014\u6539\u2014\u5199&#034;\u88ab synchronized \u5305\u6210\u4e86\u4e00\u4e2a\u4e0d\u53ef\u5206\u5272\u7684\u6574\u4f53&#xff1a;\u7ebf\u7a0b B \u60f3\u8bfb&#xff0c;\u5fc5\u987b\u7b49\u7ebf\u7a0b A \u5199\u5b8c\u653e\u9501&#xff0c;\u8bfb\u5230\u7684\u6c38\u8fdc\u662f\u6700\u65b0\u503c\u3002\u8d26&#xff0c;\u7b97\u5e73\u4e86\u3002<\/p>\n<p>\u6ce8\u610f\u4e24\u4e2a\u548c\u4e0a\u8282\u8bfe\u4e00\u8109\u76f8\u627f\u7684\u7ec6\u8282&#xff1a;<\/p>\n<li>box \u4ecd\u7136\u662f let&#xff08;\u5f15\u7528\u4e0d\u53d8&#xff09;&#xff0c;\u53ef\u53d8\u7684\u662f\u5bf9\u8c61\u5185\u90e8&#xff0c;spawn \u7684\u6355\u83b7\u89c4\u5219\u6ca1\u53d8&#xff1b;<\/li>\n<li>\u6700\u540e\u5fc5\u987b\u9010\u4e2a get() \u7b49\u9f50 10 \u4e2a\u7ebf\u7a0b&#xff0c;\u5426\u5219 main \u4e00\u7ed3\u675f\u8fdb\u7a0b\u5c31\u6536\u961f\u4e86\u3002<\/li>\n<hr \/>\n<h3>\u56db\u3001Atomic \u539f\u5b50\u7c7b\u578b<\/h3>\n<p>Mutex \u662f&#034;\u8c01\u90fd\u522b\u62a2&#xff0c;\u6392\u961f\u6765&#034;\u3002\u8fd8\u6709\u4e00\u79cd\u66f4\u8f7b\u91cf\u7684\u601d\u8def&#xff1a;\u8ba9\u53d8\u91cf\u672c\u8eab\u7684\u8bfb\u5199\u64cd\u4f5c\u5929\u751f\u4e0d\u53ef\u5206\u5272\u2014\u2014\u8fd9\u5c31\u662f\u539f\u5b50\u7c7b\u578b&#xff08;atomic&#xff0c;&#034;\u539f\u5b50&#034;\u53d6&#034;\u4e0d\u53ef\u518d\u5206&#034;\u4e4b\u610f&#xff09;\u3002<\/p>\n<h4>4.1 \u6709\u54ea\u4e9b\u539f\u5b50\u7c7b\u578b<\/h4>\n<p>std.sync \u63d0\u4f9b 9 \u4e2a&#xff1a;<\/p>\n<table>\n<tr>\u7c7b\u578b\u5305\u88c5\u7684\u666e\u901a\u7c7b\u578b<\/tr>\n<tbody>\n<tr>\n<td>AtomicBool<\/td>\n<td>Bool<\/td>\n<\/tr>\n<tr>\n<td>AtomicInt8 \/ AtomicInt16 \/ AtomicInt32 \/ AtomicInt64<\/td>\n<td>Int8 \/ Int16 \/ Int32 \/ Int64<\/td>\n<\/tr>\n<tr>\n<td>AtomicUInt8 \/ AtomicUInt16 \/ AtomicUInt32 \/ AtomicUInt64<\/td>\n<td>UInt8 \/ UInt16 \/ UInt32 \/ UInt64<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>4.2 \u6570\u503c\u578b\u539f\u5b50\u7c7b\u578b\u7684\u65b9\u6cd5<\/h4>\n<p>\u4ee5 AtomicInt64 \u4e3a\u4f8b&#xff1a;<\/p>\n<p>import std.sync.*<\/p>\n<p>main(): Int64 {<br \/>\n    let a &#061; AtomicInt64(10)<br \/>\n    println(&#034;fetchAdd \u65e7\u503c&#xff1a;${a.fetchAdd(5)}&#034;)<br \/>\n    println(&#034;\u73b0\u5728&#xff1a;${a.load()}&#034;)<br \/>\n    println(&#034;swap \u65e7\u503c&#xff1a;${a.swap(100)}&#034;)<br \/>\n    println(&#034;\u73b0\u5728&#xff1a;${a.load()}&#034;)<br \/>\n    println(&#034;CAS \u6210\u529f&#xff1f;${a.compareAndSwap(100, 200)}&#034;)<br \/>\n    println(&#034;\u73b0\u5728&#xff1a;${a.load()}&#034;)<br \/>\n    println(&#034;CAS \u5931\u8d25&#xff1f;${a.compareAndSwap(100, 999)}&#034;)<br \/>\n    println(&#034;\u73b0\u5728&#xff1a;${a.load()}&#034;)<br \/>\n    a.fetchSub(50)<br \/>\n    println(&#034;fetchSub \u540e&#xff1a;${a.load()}&#034;)<br \/>\n    return 0<br \/>\n}<\/p>\n<p>\u9010\u884c\u5b9e\u6d4b\u8f93\u51fa&#xff1a;<\/p>\n<p>fetchAdd \u65e7\u503c&#xff1a;10<br \/>\n\u73b0\u5728&#xff1a;15<br \/>\nswap \u65e7\u503c&#xff1a;15<br \/>\n\u73b0\u5728&#xff1a;100<br \/>\nCAS \u6210\u529f&#xff1f;true<br \/>\n\u73b0\u5728&#xff1a;200<br \/>\nCAS \u5931\u8d25&#xff1f;false<br \/>\n\u73b0\u5728&#xff1a;200<br \/>\nfetchSub \u540e&#xff1a;150<\/p>\n<p>\u65b9\u6cd5\u6e05\u5355&#xff1a;<\/p>\n<table>\n<tr>\u65b9\u6cd5\u4f5c\u7528\u8fd4\u56de\u503c<\/tr>\n<tbody>\n<tr>\n<td>load()<\/td>\n<td>\u8bfb\u5f53\u524d\u503c<\/td>\n<td>\u5f53\u524d\u503c<\/td>\n<\/tr>\n<tr>\n<td>store(v)<\/td>\n<td>\u5199\u5165\u65b0\u503c<\/td>\n<td>\u65e0<\/td>\n<\/tr>\n<tr>\n<td>swap(v)<\/td>\n<td>\u6362\u6210\u65b0\u503c<\/td>\n<td>\u65e7\u503c<\/td>\n<\/tr>\n<tr>\n<td>fetchAdd(v) \/ fetchSub(v)<\/td>\n<td>\u52a0 \/ \u51cf<\/td>\n<td>\u65e7\u503c<\/td>\n<\/tr>\n<tr>\n<td>fetchAnd(v) \/ fetchOr(v) \/ fetchXor(v)<\/td>\n<td>\u4f4d\u4e0e \/ \u4f4d\u6216 \/ \u4f4d\u5f02\u6216<\/td>\n<td>\u65e7\u503c<\/td>\n<\/tr>\n<tr>\n<td>compareAndSwap(expect, new)<\/td>\n<td>\u5f53\u524d\u503c\u7b49\u4e8e expect \u624d\u6362\u6210 new<\/td>\n<td>\u662f\u5426\u4ea4\u6362\u6210\u529f&#xff08;Bool&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8\u610f\u4e24\u4e2a\u521d\u5b66\u8005\u6700\u5bb9\u6613\u8e29\u7684\u70b9&#xff1a;<\/p>\n<li>fetchAdd \u8fd4\u56de\u7684\u662f\u65e7\u503c&#xff0c;\u4e0d\u662f\u52a0\u5b8c\u7684\u503c\u2014\u2014\u4e0a\u9762\u8f93\u51fa\u91cc fetchAdd(5) \u6253\u5370 10&#xff0c;\u4f46\u63a5\u7740 load() \u662f 15&#xff1b;<\/li>\n<li>\u539f\u5b50\u7c7b\u578b\u6ca1\u6709 .value \u5b57\u6bb5&#xff0c;\u8bfb\u503c\u5fc5\u987b\u7528 load()\u3002\u76f4\u63a5\u5199 a.value \u7f16\u8bd1\u5668\u4f1a\u62a5&#xff1a;error: can not access field &#039;value&#039;\u3002<\/li>\n<p>AtomicBool \u7528\u5f97\u6700\u591a\u7684\u662f compareAndSwap&#xff08;\u7b80\u79f0 CAS&#xff09;&#xff1a;<\/p>\n<p>import std.sync.*<\/p>\n<p>main(): Int64 {<br \/>\n    let b &#061; AtomicBool(false)<br \/>\n    println(&#034;Bool CAS&#xff1a;${b.compareAndSwap(false, true)}&#034;)<br \/>\n    println(&#034;Bool \u503c&#xff1a;${b.load()}&#034;)<br \/>\n    b.store(false)<br \/>\n    println(&#034;store \u540e&#xff1a;${b.load()}&#034;)<br \/>\n    return 0<br \/>\n}<\/p>\n<p>Bool CAS&#xff1a;true<br \/>\nBool \u503c&#xff1a;true<br \/>\nstore \u540e&#xff1a;false<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u4fee\u590d CounterBox&#xff08;\u65b9\u6848\u4e8c&#xff1a;AtomicInt64&#xff09;<\/h3>\n<p>\u8ba1\u6570\u5668\u53ea\u6709\u4e00\u4e2a\u6574\u6570\u5728\u53d8&#xff0c;\u7528\u539f\u5b50\u7c7b\u578b\u6bd4\u52a0\u9501\u66f4\u76f4\u63a5&#xff1a;<\/p>\n<p>import std.sync.*<br \/>\nimport std.collection.ArrayList<\/p>\n<p>class AtomicCounter {<br \/>\n    let count &#061; AtomicInt64(0)<\/p>\n<p>    func addOne() {<br \/>\n        count.fetchAdd(1)<br \/>\n    }<br \/>\n}<\/p>\n<p>main(): Int64 {<br \/>\n    let box &#061; AtomicCounter()<br \/>\n    let futures &#061; ArrayList&lt;Future&lt;Unit&gt;&gt;()<br \/>\n    for (_ in 1..&#061;10) {<br \/>\n        futures.add(spawn {<br \/>\n            for (_ in 1..&#061;10000) {<br \/>\n                box.addOne()<br \/>\n            }<br \/>\n        })<br \/>\n    }<br \/>\n    for (f in futures) {<br \/>\n        f.get()<br \/>\n    }<br \/>\n    println(&#034;\u671f\u671b 100000&#xff0c;\u5b9e\u9645 ${box.count.load()}&#034;)<br \/>\n    return 0<br \/>\n}<\/p>\n<p>\u671f\u671b 100000&#xff0c;\u5b9e\u9645 100000<\/p>\n<p>fetchAdd(1) \u8fd9\u4e00\u4e2a\u8c03\u7528\u5c31\u5b8c\u6210\u4e86&#034;\u8bfb\u2014\u52a0\u2014\u5199&#034;&#xff0c;\u4e2d\u95f4\u4e0d\u53ef\u80fd\u63d2\u8fdb\u7b2c\u4e8c\u4e2a\u7ebf\u7a0b&#xff0c;\u6240\u4ee5\u8fde\u9501\u90fd\u7701\u4e86\u3002\u8bfb\u7ed3\u679c\u65f6\u8bb0\u5f97\u7528 load()&#xff0c;\u4e0d\u80fd\u76f4\u63a5\u5199 box.count\u3002<\/p>\n<p>\u4e24\u79cd\u65b9\u6848\u600e\u4e48\u9009&#xff1f;<\/p>\n<ul>\n<li>\u53ea\u4fdd\u62a4\u4e00\u4e2a\u6570\u5b57&#xff08;\u8ba1\u6570\u5668\u3001\u5e8f\u53f7\u3001\u5f00\u5173\u6807\u5fd7&#xff09;\u2192 \u7528 Atomic&#xff0c;\u66f4\u8f7b\u3001\u66f4\u5feb&#xff1b;<\/li>\n<li>\u8981\u4fdd\u62a4\u4e00\u6bb5\u903b\u8f91\u6216\u591a\u4e2a\u5b57\u6bb5&#xff08;\u6bd4\u5982&#034;x \u548c y \u5fc5\u987b\u4e00\u8d77\u6539&#034;\u3001\u201c\u5148\u5224\u65ad\u518d\u4fee\u6539\u201d&#xff09;\u2192 \u7528 Mutex &#043; synchronized\u3002\u4e00\u628a\u9501\u91cc\u60f3\u5305\u51e0\u884c\u5305\u51e0\u884c&#xff0c;\u539f\u5b50\u7c7b\u578b\u7ba1\u4e0d\u4e86\u591a\u884c\u903b\u8f91\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u516d\u3001\u7ebf\u7a0b\u95f4\u7684\u7b49\u5f85\u4e0e\u901a\u77e5&#xff1a;Condition \u6761\u4ef6\u53d8\u91cf<\/h3>\n<p>\u4e92\u65a5\u9501\u89e3\u51b3\u4e86&#034;\u62a2&#034;\u7684\u95ee\u9898&#xff0c;\u4f46\u5e76\u53d1\u91cc\u8fd8\u6709\u4e00\u7c7b&#034;\u7b49&#034;\u7684\u95ee\u9898&#xff1a;\u6d88\u8d39\u8005\u7ebf\u7a0b\u8981\u7b49\u751f\u4ea7\u8005\u628a\u6570\u636e\u51c6\u5907\u597d\u3002\u4e00\u76f4\u5faa\u73af\u95ee&#034;\u597d\u4e86\u5417&#xff1f;\u597d\u4e86\u5417&#xff1f;&#034;&#xff08;\u5fd9\u7b49&#xff09;\u65e2\u6d6a\u8d39 CPU&#xff0c;\u53c8\u62ff\u7740\u9501\u4e0d\u653e\u3002<\/p>\n<h4>6.1 \u4e00\u4e2a\u5b8c\u6574\u7684\u7b49\u5f85\u2014\u901a\u77e5<\/h4>\n<p>\u4ed3\u9889\u7684\u89e3\u6cd5\u662f Condition \u6761\u4ef6\u53d8\u91cf&#xff1a;\u7b49\u7684\u4eba\u8c03\u7528 wait() \u7761\u8fc7\u53bb&#xff0c;\u51c6\u5907\u597d\u7684\u4eba\u8c03\u7528 notify() \u628a\u5b83\u53eb\u9192\u3002<\/p>\n<p>import std.sync.*<br \/>\nimport std.collection.ArrayList<\/p>\n<p>main(): Int64 {<br \/>\n    let lock &#061; Mutex()<br \/>\n    lock.lock()<br \/>\n    let notEmpty &#061; lock.condition()   \/\/ \u6761\u4ef6\u53d8\u91cf\u5fc5\u987b\u7531&#034;\u6301\u9501\u7ebf\u7a0b&#034;\u521b\u5efa<br \/>\n    lock.unlock()<br \/>\n    let queue &#061; ArrayList&lt;Int64&gt;()<\/p>\n<p>    \/\/ \u6d88\u8d39\u8005&#xff1a;\u961f\u5217\u7a7a\u5c31\u7b49<br \/>\n    let consumer &#061; spawn {<br \/>\n        synchronized (lock) {<br \/>\n            while (queue.size &#061;&#061; 0) {<br \/>\n                notEmpty.wait()       \/\/ \u7761&#xff1a;\u653e\u9501\u3001\u7b49\u4eba notify<br \/>\n            }<br \/>\n            println(&#034;\u6d88\u8d39\u8005\u62ff\u5230&#xff1a;${queue[0]}&#034;)<br \/>\n        }<br \/>\n    }<\/p>\n<p>    sleep(Duration.millisecond * 200)<\/p>\n<p>    \/\/ \u751f\u4ea7\u8005&#xff1a;\u653e\u6570\u636e&#xff0c;\u53eb\u9192\u6d88\u8d39\u8005<br \/>\n    synchronized (lock) {<br \/>\n        queue.add(42)<br \/>\n        notEmpty.notify()<br \/>\n        println(&#034;\u751f\u4ea7\u8005\u653e\u5165&#xff1a;42&#034;)<br \/>\n    }<br \/>\n    consumer.get()<br \/>\n    return 0<br \/>\n}<\/p>\n<p>\u751f\u4ea7\u8005\u653e\u5165&#xff1a;42<br \/>\n\u6d88\u8d39\u8005\u62ff\u5230&#xff1a;42<\/p>\n<p>\u6267\u884c\u8fc7\u7a0b\u662f\u8fd9\u6837\u7684&#xff1a;<\/p>\n<li>\u6d88\u8d39\u8005\u5148\u8fdb synchronized&#xff0c;\u53d1\u73b0\u961f\u5217\u662f\u7a7a\u7684&#xff0c;\u6267\u884c wait()\u2014\u2014\u7761\u8fc7\u53bb&#xff0c;\u540c\u65f6\u628a\u9501\u4ea4\u51fa\u6765&#xff08;\u4e0d\u7136\u751f\u4ea7\u8005\u6c38\u8fdc\u8fdb\u4e0d\u6765&#xff0c;\u5c31\u6b7b\u9501\u4e86&#xff09;&#xff1b;<\/li>\n<li>200 \u6beb\u79d2\u540e\u751f\u4ea7\u8005\u62ff\u5230\u9501\u3001\u653e\u5165 42\u3001notify() \u53eb\u9192\u6d88\u8d39\u8005&#xff1b;<\/li>\n<li>\u6d88\u8d39\u8005\u91cd\u65b0\u62ff\u5230\u9501&#xff0c;\u4ece wait() \u9192\u6765&#xff0c;\u518d\u770b\u4e00\u773c while \u6761\u4ef6\u2014\u2014\u73b0\u5728\u4e0d\u7a7a\u4e86&#xff0c;\u9000\u51fa\u5faa\u73af\u53d6\u6570\u636e\u3002<\/li>\n<h4>6.2 \u4e09\u4e2a\u5fc5\u987b\u8bb0\u4f4f\u7684\u89c4\u77e9<\/h4>\n<p>\u89c4\u77e9\u4e00&#xff1a;\u6761\u4ef6\u53d8\u91cf\u53ea\u80fd\u7531\u6301\u9501\u7ebf\u7a0b\u521b\u5efa\u3002<\/p>\n<p>lock.condition() \u8981\u6c42\u8c03\u7528\u65f6\u672c\u7ebf\u7a0b\u5df2\u7ecf\u62ff\u7740\u8fd9\u628a\u9501&#xff0c;\u4e0d\u7136\u540e\u679c\u662f\u4e00\u4e2a\u8fd0\u884c\u65f6\u5f02\u5e38&#xff08;\u5c31\u662f\u4e0a\u9762 main \u91cc\u5148 lock() \u518d\u521b\u5efa\u518d unlock() \u7684\u539f\u56e0&#xff09;&#xff1a;<\/p>\n<p>IllegalSynchronizationStateException: Mutex is not locked by current thread.<\/p>\n<p>\u89c4\u77e9\u4e8c&#xff1a;wait() \u5fc5\u987b\u653e\u5728 while \u5faa\u73af\u91cc&#xff0c;\u4e0d\u80fd\u7528 if\u3002<\/p>\n<p>\u7ebf\u7a0b\u4ece wait() \u9192\u6765\u65f6&#xff0c;\u6761\u4ef6\u4e0d\u4e00\u5b9a\u8fd8\u6210\u7acb&#xff08;\u53ef\u80fd\u88ab\u522b\u7684\u7ebf\u7a0b\u62a2\u5148\u6539\u56de\u53bb\u4e86&#xff0c;\u4e5f\u53ef\u80fd\u5b58\u5728\u865a\u5047\u5524\u9192&#xff09;\u3002\u7528 while&#xff0c;\u9192\u6765\u540e\u4f1a\u518d\u68c0\u67e5\u4e00\u6b21\u6761\u4ef6&#xff0c;\u4e0d\u6210\u7acb\u5c31\u7ee7\u7eed\u7761&#xff1b;\u7528 if \u5c31\u76f4\u63a5\u5f80\u4e0b\u51b2\u4e86\u3002<\/p>\n<p>\u89c4\u77e9\u4e09&#xff1a;wait() \/ notify() \u90fd\u8981\u5728 synchronized (lock) \u5757\u91cc\u8c03\u7528\u3002<\/p>\n<p>notify() \u53ea\u53eb\u9192\u4e00\u4e2a\u7b49\u5f85\u8005&#xff1b;\u60f3\u5168\u53eb\u9192\u7528 notifyAll()\u3002\u4e00\u4e2a\u751f\u4ea7\u8005\u914d\u4e00\u4e2a\u6d88\u8d39\u8005\u65f6 notify() \u5c31\u591f&#xff1b;\u591a\u4e2a\u6d88\u8d39\u8005\u62a2\u4efb\u52a1\u65f6\u8981\u7528 notifyAll()\u3002<\/p>\n<h4>6.3 \u5e26\u8d85\u65f6\u7684\u7b49\u5f85<\/h4>\n<p>\u4e0d\u60f3\u65e0\u9650\u7b49&#xff1f;\u7ed9 wait \u4f20 timeout: \u53c2\u6570&#xff0c;\u8fd4\u56de Bool&#xff1a;\u88ab\u901a\u77e5\u5524\u9192\u8fd4\u56de true&#xff0c;\u8d85\u65f6\u8fd4\u56de false\u3002<\/p>\n<p>import std.sync.*<\/p>\n<p>main(): Int64 {<br \/>\n    let lock &#061; Mutex()<br \/>\n    lock.lock()<br \/>\n    let cond &#061; lock.condition()<br \/>\n    lock.unlock()<br \/>\n    synchronized (lock) {<br \/>\n        let r &#061; cond.wait(timeout: Duration.millisecond * 100)<br \/>\n        println(&#034;\u8d85\u65f6\u7b49\u5f85\u8fd4\u56de&#xff1a;${r}&#034;)<br \/>\n    }<br \/>\n    return 0<br \/>\n}<\/p>\n<p>\u8d85\u65f6\u7b49\u5f85\u8fd4\u56de&#xff1a;false<\/p>\n<p>\u6ce8\u610f\u53c2\u6570\u540d timeout: \u4e0d\u80fd\u7701&#xff0c;\u6f0f\u5199\u4f1a\u62a5 error: missing argument prefix &#039;timeout:&#039; for named parameter\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001Channel \u4e4b\u8c1c&#xff1a;1.2.0 \u5b9e\u6d4b\u6ca1\u6709&#xff0c;\u90a3\u5c31\u81ea\u5df1\u9020\u4e00\u4e2a<\/h3>\n<h4>7.1 \u5148\u8bf4\u7ed3\u8bba<\/h4>\n<p>\u5f88\u591a\u5e76\u53d1\u8bed\u8a00&#xff08;\u6bd4\u5982 Go&#xff09;\u63d0\u5021\u4e00\u79cd\u6a21\u578b&#xff1a;\u201c\u4e0d\u8981\u901a\u8fc7\u5171\u4eab\u5185\u5b58\u6765\u901a\u4fe1&#xff0c;\u800c\u8981\u901a\u8fc7\u901a\u4fe1\u6765\u5171\u4eab\u5185\u5b58\u201d\u2014\u2014\u7ebf\u7a0b\u4e4b\u95f4\u4e0d\u76f4\u63a5\u62a2\u53d8\u91cf&#xff0c;\u800c\u662f\u5f80\u4e00\u4e2a\u53eb Channel&#xff08;\u901a\u9053&#xff09; \u7684\u7ba1\u5b50\u91cc\u53d1\u6d88\u606f\u3001\u6536\u6d88\u606f&#xff0c;\u6570\u636e\u540c\u4e00\u65f6\u523b\u53ea\u5728\u4e00\u4e2a\u7ebf\u7a0b\u624b\u91cc&#xff0c;\u4ece\u6839\u4e0a\u907f\u514d\u6570\u636e\u7ade\u4e89\u3002<\/p>\n<p>\u4e0a\u8282\u8bfe\u7684\u9884\u544a\u8bf4\u8fd9\u8282\u8bfe\u8bb2 Channel\u3002\u5907\u8bfe\u7684\u65f6\u5019\u6211\u4eec\u505a\u4e86\u4e00\u4ef6\u672c\u7cfb\u5217\u4e00\u8d2f\u7684\u4e8b&#xff1a;\u5728\u4ed3\u9889 SDK 1.2.0 \u91cc\u4eb2\u624b\u8bd5\u3002\u7ed3\u679c\u662f&#xff1a;<\/p>\n<p>import std.sync.*<\/p>\n<p>main(): Int64 {<br \/>\n    let ch &#061; Channel&lt;Int64&gt;()<br \/>\n    ch.send(1)<br \/>\n    return 0<br \/>\n}<\/p>\n<p>error: undeclared identifier &#039;Channel&#039;<\/p>\n<p>\u622a\u81f3\u4ed3\u9889 SDK 1.2.0&#xff0c;\u6807\u51c6\u5e93\u91cc\u8fd8\u6ca1\u6709\u516c\u5f00\u7684 Channel \u7c7b\u578b&#xff08;std.sync \u91cc\u6709\u9501\u3001\u6761\u4ef6\u53d8\u91cf\u3001\u539f\u5b50\u7c7b\u578b\u3001\u4fe1\u53f7\u91cf\u7b49&#xff0c;\u4f46\u6ca1\u6709\u901a\u9053&#xff09;\u3002\u7f51\u4e0a\u4e0d\u5c11\u6587\u7ae0\u91cc\u7684 import concurrency\u3001channel.send() \u4e4b\u7c7b\u5199\u6cd5\u5728 1.2.0 \u4e0b\u90fd\u7f16\u4e0d\u8fc7&#xff0c;\u8bf7\u5927\u5bb6\u4ee5\u672c\u673a SDK \u7684\u5b9e\u6d4b\u4e3a\u51c6\u3002<\/p>\n<p>\u90a3&#034;\u901a\u9053&#034;\u8fd9\u4e2a\u6982\u5ff5\u5c31\u5b66\u4e0d\u4e86\u4e86\u5417&#xff1f;\u6070\u6070\u76f8\u53cd\u2014\u2014\u7406\u89e3\u4e86\u9501\u548c\u6761\u4ef6\u53d8\u91cf&#xff0c;\u4f60\u4f1a\u53d1\u73b0\u901a\u9053\u4e00\u70b9\u90fd\u4e0d\u795e\u79d8&#xff1a;\u5b83\u5c31\u662f\u4e00\u4e2a\u52a0\u4e86\u9501\u7684\u961f\u5217&#xff0c;\u914d\u4e0a\u4e24\u4e2a\u6761\u4ef6\u53d8\u91cf\u3002 \u6211\u4eec\u73b0\u5728\u5c31\u4eb2\u624b\u5b9e\u73b0\u4e00\u4e2a\u3002<\/p>\n<h4>7.2 \u5b9e\u73b0\u4e00\u4e2a BlockingQueue&#xff08;\u963b\u585e\u961f\u5217&#xff09;<\/h4>\n<p>\u901a\u9053\u6700\u6838\u5fc3\u7684\u884c\u4e3a\u6709\u4e24\u4e2a&#xff1a;<\/p>\n<ul>\n<li>\u53d1\u9001&#xff1a;\u961f\u5217\u6ee1\u4e86\u5c31\u7b49&#xff08;\u7b49\u6d88\u8d39\u8005\u817e\u4f4d\u7f6e&#xff09;&#xff1b;<\/li>\n<li>\u63a5\u6536&#xff1a;\u961f\u5217\u7a7a\u4e86\u5c31\u7b49&#xff08;\u7b49\u751f\u4ea7\u8005\u653e\u6570\u636e&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u7528&#034;\u4e00\u628a\u9501 &#043; \u4e24\u4e2a\u6761\u4ef6\u53d8\u91cf &#043; \u7b2c 8 \u8bfe\u7684 ArrayList&#034;\u5b9e\u73b0\u3002\u6ce8\u610f\u5220\u9664\u961f\u9996\u5143\u7d20\u7528\u7684\u662f\u7b2c 8 \u8bfe\u6559\u8fc7\u7684\u533a\u95f4\u5199\u6cd5 buf.remove(0..1)&#xff1a;<\/p>\n<p>import std.sync.*<br \/>\nimport std.collection.ArrayList<\/p>\n<p>class BlockingQueue&lt;T&gt; {<br \/>\n    let buf &#061; ArrayList&lt;T&gt;()<br \/>\n    let capacity: Int64<br \/>\n    let lock &#061; Mutex()<br \/>\n    let notEmpty: Condition<br \/>\n    let notFull: Condition<\/p>\n<p>    init(capacity: Int64) {<br \/>\n        this.capacity &#061; capacity<br \/>\n        lock.lock()<br \/>\n        this.notEmpty &#061; lock.condition()<br \/>\n        this.notFull &#061; lock.condition()<br \/>\n        lock.unlock()<br \/>\n    }<\/p>\n<p>    func put(item: T) {<br \/>\n        synchronized (lock) {<br \/>\n            while (buf.size &gt;&#061; capacity) {<br \/>\n                notFull.wait()              \/\/ \u961f\u5217\u6ee1&#xff1a;\u7b49\u6d88\u8d39\u8005\u53d6\u8d70<br \/>\n            }<br \/>\n            buf.add(item)<br \/>\n            notEmpty.notify()               \/\/ \u653e\u5165\u540e&#xff1a;\u53eb\u9192\u7b49\u6570\u636e\u7684\u4eba<br \/>\n        }<br \/>\n    }<\/p>\n<p>    func take(): T {<br \/>\n        synchronized (lock) {<br \/>\n            while (buf.size &#061;&#061; 0) {<br \/>\n                notEmpty.wait()             \/\/ \u961f\u5217\u7a7a&#xff1a;\u7b49\u751f\u4ea7\u8005\u653e\u5165<br \/>\n            }<br \/>\n            let item &#061; buf[0]<br \/>\n            buf.remove(0..1)<br \/>\n            notFull.notify()                \/\/ \u53d6\u8d70\u540e&#xff1a;\u53eb\u9192\u7b49\u4f4d\u7f6e\u7684\u4eba<br \/>\n            return item<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u5bf9\u7167 Channel \u7684\u6982\u5ff5\u770b\u8fd9\u4efd\u5b9e\u73b0&#xff1a;<\/p>\n<table>\n<tr>Channel \u6982\u5ff5\u672c\u5b9e\u73b0\u7684\u5bf9\u5e94\u7269<\/tr>\n<tbody>\n<tr>\n<td>\u53d1\u9001 send \/ \u63a5\u6536 receive<\/td>\n<td>put \/ take<\/td>\n<\/tr>\n<tr>\n<td>\u5e26\u7f13\u51b2\u901a\u9053&#xff0c;\u5bb9\u91cf n<\/td>\n<td>BlockingQueue&lt;T&gt;(n)<\/td>\n<\/tr>\n<tr>\n<td>\u53d1\u9001\u65f6\u7f13\u51b2\u6ee1\u5219\u963b\u585e<\/td>\n<td>put \u91cc\u7684 notFull.wait()<\/td>\n<\/tr>\n<tr>\n<td>\u63a5\u6536\u65f6\u7f13\u51b2\u7a7a\u5219\u963b\u585e<\/td>\n<td>take \u91cc\u7684 notEmpty.wait()<\/td>\n<\/tr>\n<tr>\n<td>\u65e0\u7f13\u51b2\u901a\u9053&#xff08;\u53d1\u9001\u65b9\u548c\u63a5\u6536\u65b9\u5f53\u9762\u4ea4\u63a5&#xff09;<\/td>\n<td>\u5bb9\u91cf\u4f20 1 \u5373\u53ef\u8fd1\u4f3c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>7.3 \u8dd1\u4e00\u4e2a\u751f\u4ea7\u8005\u2014\u6d88\u8d39\u8005<\/h4>\n<p>\u4e00\u4e2a\u751f\u4ea7\u8005\u653e 5 \u4e2a\u6570&#xff0c;\u4e00\u4e2a\u6d88\u8d39\u8005\u6536 5 \u4e2a\u6570\u3002\u4e3a\u4e86\u8ba9\u8f93\u51fa\u7a33\u5b9a\u53ef\u5bf9\u7167&#xff0c;\u53ea\u8ba9\u6d88\u8d39\u8005\u6253\u5370&#xff1a;<\/p>\n<p>main(): Int64 {<br \/>\n    let q &#061; BlockingQueue&lt;Int64&gt;(2)<\/p>\n<p>    let producer &#061; spawn {<br \/>\n        for (i in 1..&#061;5) {<br \/>\n            q.put(i)<br \/>\n        }<br \/>\n    }<br \/>\n    let consumer &#061; spawn {<br \/>\n        for (_ in 1..&#061;5) {<br \/>\n            let v &#061; q.take()<br \/>\n            println(&#034;\u6536\u5230&#xff1a;${v}&#034;)<br \/>\n        }<br \/>\n    }<br \/>\n    producer.get()<br \/>\n    consumer.get()<br \/>\n    println(&#034;\u6536\u5b8c\u4e86&#034;)<br \/>\n    return 0<br \/>\n}<\/p>\n<p>\u8fde\u8dd1\u4e09\u6b21&#xff0c;\u8f93\u51fa\u90fd\u4e00\u6837&#xff1a;<\/p>\n<p>\u6536\u5230&#xff1a;1<br \/>\n\u6536\u5230&#xff1a;2<br \/>\n\u6536\u5230&#xff1a;3<br \/>\n\u6536\u5230&#xff1a;4<br \/>\n\u6536\u5230&#xff1a;5<br \/>\n\u6536\u5b8c\u4e86<\/p>\n<p>\u751f\u4ea7\u8005\u653e\u5f97\u5feb\u4e5f\u6ca1\u7528\u2014\u2014\u961f\u5217\u5bb9\u91cf\u53ea\u6709 2&#xff0c;\u653e\u6ee1\u5c31\u7761&#xff1b;\u6d88\u8d39\u8005\u53d6\u8d70\u4e00\u4e2a\u624d\u817e\u51fa\u4e00\u4e2a\u4f4d\u7f6e\u3002\u867d\u7136\u4e24\u4e2a\u7ebf\u7a0b\u5728\u5e76\u53d1\u63a8\u8fdb&#xff0c;\u4f46\u6570\u636e\u7ecf\u8fc7\u961f\u5217\u65f6\u4e25\u683c\u5148\u8fdb\u5148\u51fa&#xff0c;\u6240\u4ee5\u6d88\u8d39\u8005\u6536\u5230\u7684\u987a\u5e8f\u6052\u4e3a 1\u21925\u3002\u8fd9\u5c31\u662f&#034;\u7528\u901a\u4fe1\u6765\u5171\u4eab\u5185\u5b58&#034;\u7684\u96cf\u5f62&#xff1a;\u8c01\u62ff\u5230\u961f\u5217\u91cc\u7684\u6570\u636e&#xff0c;\u8c01\u624d\u6709\u6743\u5904\u7406\u5b83\u3002<\/p>\n<p>&#x1f538; \u8fd9\u4e2a\u7c7b\u523b\u610f\u53ea\u4fdd\u7559\u4e86\u901a\u9053\u6700\u672c\u8d28\u7684\u9aa8\u67b6&#xff0c;\u6ca1\u6709\u505a\u5173\u95ed&#xff08;close&#xff09;\u3001\u591a\u6d88\u8d39\u8005\u5524\u9192\u7b49\u5de5\u7a0b\u7ec6\u8282\u3002\u7b49\u5b98\u65b9 Channel \u5728\u540e\u7eed SDK \u7248\u672c\u843d\u5730\u540e&#xff0c;\u4f18\u5148\u7528\u5b98\u65b9\u5b9e\u73b0&#xff1b;\u4f46\u53ea\u8981\u7406\u89e3\u4e86\u8fd9\u4efd\u5b9e\u73b0&#xff0c;\u4ee5\u540e\u7528\u8c01\u7684\u901a\u9053\u90fd\u4e00\u6837\u3002<\/p>\n<hr \/>\n<h3>\u516b\u3001\u5176\u5b83\u540c\u6b65\u539f\u8bed\u901f\u89c8<\/h3>\n<h4>8.1 Semaphore \u4fe1\u53f7\u91cf&#xff1a;\u9650\u6d41<\/h4>\n<p>Semaphore(n) \u53ef\u4ee5\u7406\u89e3\u4e3a\u4e00\u6c93\u5171 n \u5f20\u7684&#034;\u901a\u884c\u8bc1&#034;&#xff1a;acquire() \u9886\u4e00\u5f20&#xff08;\u53d1\u5b8c\u4e86\u5c31\u7b49&#xff09;&#xff0c;release() \u8fd8\u4e00\u5f20\u3002\u5178\u578b\u7528\u9014\u662f\u9650\u6d41\u2014\u2014\u6bd4\u5982\u540c\u65f6\u53ea\u5141\u8bb8 2 \u4e2a\u7ebf\u7a0b\u4e0b\u8f7d&#xff1a;<\/p>\n<p>import std.sync.*<\/p>\n<p>main(): Int64 {<br \/>\n    let sem &#061; Semaphore(2)<br \/>\n    sem.acquire()<br \/>\n    sem.acquire()<br \/>\n    println(&#034;\u8bb8\u53ef\u7528\u5b8c\u65f6 tryAcquire&#xff1a;${sem.tryAcquire()}&#034;)<br \/>\n    sem.release()<br \/>\n    println(&#034;\u91ca\u653e\u4e00\u4e2a\u540e tryAcquire&#xff1a;${sem.tryAcquire()}&#034;)<br \/>\n    return 0<br \/>\n}<\/p>\n<p>\u8bb8\u53ef\u7528\u5b8c\u65f6 tryAcquire&#xff1a;false<br \/>\n\u91ca\u653e\u4e00\u4e2a\u540e tryAcquire&#xff1a;true<\/p>\n<ul>\n<li>acquire()&#xff1a;\u9886\u901a\u884c\u8bc1&#xff0c;\u6ca1\u6709\u5c31\u7b49&#xff1b;<\/li>\n<li>tryAcquire()&#xff1a;\u8bd5\u9886&#xff0c;\u6ca1\u6709\u7acb\u523b\u8fd4\u56de false&#xff1b;<\/li>\n<li>release()&#xff1a;\u8fd8\u56de\u4e00\u5f20\u3002<\/li>\n<\/ul>\n<p>\u591a\u7ebf\u7a0b\u7528\u6cd5\u5c31\u662f\u6a21\u677f&#xff1a;\u8fdb\u4e34\u754c\u533a\u524d acquire()&#xff0c;\u51fa\u6765 release()&#xff08;\u52a1\u5fc5\u6210\u5bf9&#xff09;\u3002\u8bfe\u540e\u7ec3\u4e60\u7b2c 4 \u9898\u4f1a\u7528\u5b83\u7edf\u8ba1&#034;\u540c\u65f6\u5728\u573a\u4eba\u6570\u7684\u5cf0\u503c&#034;\u3002<\/p>\n<h4>8.2 Barrier \u6805\u680f&#xff1a;\u7b49\u4eba\u5230\u9f50\u518d\u4e00\u8d77\u8d70<\/h4>\n<p>Barrier(n) \u662f\u4e00\u4e2a\u96c6\u5408\u70b9&#xff1a;n \u4e2a\u7ebf\u7a0b\u90fd\u5230\u8fbe&#xff08;\u90fd\u8c03\u7528 wait()&#xff09;\u4e4b\u524d&#xff0c;\u5927\u5bb6\u4e00\u8d77\u7b49&#xff1b;\u6700\u540e\u4e00\u4e2a\u5230\u7684\u77ac\u95f4&#xff0c;\u5168\u4f53\u540c\u65f6\u653e\u884c\u3002\u50cf\u65c5\u6e38\u56e2&#034;\u4eba\u9f50\u4e86\u518d\u53d1\u8f66&#034;&#xff1a;<\/p>\n<p>import std.sync.*<br \/>\nimport std.collection.ArrayList<\/p>\n<p>main(): Int64 {<br \/>\n    let barrier &#061; Barrier(3)<br \/>\n    let futures &#061; ArrayList&lt;Future&lt;Unit&gt;&gt;()<br \/>\n    for (i in 1..&#061;3) {<br \/>\n        futures.add(spawn {<br \/>\n            println(&#034;\u7ebf\u7a0b ${i} \u5230\u8fbe\u96c6\u5408\u70b9&#034;)<br \/>\n            barrier.wait()<br \/>\n            println(&#034;\u7ebf\u7a0b ${i} \u4e00\u8d77\u51fa\u53d1&#034;)<br \/>\n        })<br \/>\n    }<br \/>\n    for (f in futures) {<br \/>\n        f.get()<br \/>\n    }<br \/>\n    return 0<br \/>\n}<\/p>\n<p>\u4e00\u6b21\u5b9e\u6d4b\u8f93\u51fa&#xff1a;<\/p>\n<p>\u7ebf\u7a0b 3 \u5230\u8fbe\u96c6\u5408\u70b9<br \/>\n\u7ebf\u7a0b 1 \u5230\u8fbe\u96c6\u5408\u70b9<br \/>\n\u7ebf\u7a0b 2 \u5230\u8fbe\u96c6\u5408\u70b9<br \/>\n\u7ebf\u7a0b 3 \u4e00\u8d77\u51fa\u53d1<br \/>\n\u7ebf\u7a0b 1 \u4e00\u8d77\u51fa\u53d1<br \/>\n\u7ebf\u7a0b 2 \u4e00\u8d77\u51fa\u53d1<\/p>\n<p>\u7ebf\u7a0b\u7f16\u53f7\u7684\u5148\u540e\u987a\u5e8f\u6bcf\u6b21\u53ef\u80fd\u4e0d\u540c&#xff08;\u8001\u89c4\u77e9&#xff1a;\u8c03\u5ea6\u5668\u8bf4\u4e86\u7b97&#xff09;&#xff0c;\u4f46\u6709\u4e00\u6761\u89c4\u5f8b\u94c1\u6253\u4e0d\u53d8&#xff1a;\u4e09\u884c&#034;\u5230\u8fbe\u96c6\u5408\u70b9&#034;\u4e00\u5b9a\u5168\u90e8\u51fa\u73b0\u4e4b\u540e&#xff0c;\u624d\u4f1a\u51fa\u73b0\u4efb\u4f55\u4e00\u884c&#034;\u4e00\u8d77\u51fa\u53d1&#034;\u3002\u8fd9\u6b63\u662f\u6805\u680f\u4fdd\u8bc1\u7684\u3002<\/p>\n<h4>8.3 ReadWriteLock \u8bfb\u5199\u9501&#xff1a;\u8bfb\u5171\u4eab\u3001\u5199\u72ec\u5360<\/h4>\n<p>ReadWriteLock \u91cc\u6709\u4e24\u628a\u9501&#xff1a;readLock&#xff08;\u8bfb\u9501&#xff09;\u548c writeLock&#xff08;\u5199\u9501&#xff09;\u3002\u89c4\u5219\u662f&#xff1a;\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u6301\u8bfb\u9501&#xff0c;\u4f46\u5199\u9501\u540c\u4e00\u65f6\u523b\u53ea\u80fd\u4e00\u4e2a\u7ebf\u7a0b\u6301\u6709&#xff0c;\u4e14\u6301\u5199\u9501\u65f6\u522b\u4eba\u8fde\u8bfb\u90fd\u4e0d\u80fd\u8bfb\u3002\u9002\u5408&#034;\u8bfb\u591a\u5199\u5c11&#034;\u7684\u6570\u636e&#xff08;\u6bd4\u5982\u914d\u7f6e\u8868&#xff09;&#xff1a;<\/p>\n<p>import std.sync.*<\/p>\n<p>main(): Int64 {<br \/>\n    let rw &#061; ReadWriteLock()<br \/>\n    rw.readLock.lock()<br \/>\n    println(&#034;\u62ff\u5230\u8bfb\u9501&#034;)<br \/>\n    rw.readLock.unlock()<br \/>\n    rw.writeLock.lock()<br \/>\n    println(&#034;\u62ff\u5230\u5199\u9501&#034;)<br \/>\n    rw.writeLock.unlock()<br \/>\n    return 0<br \/>\n}<\/p>\n<p>\u62ff\u5230\u8bfb\u9501<br \/>\n\u62ff\u5230\u5199\u9501<\/p>\n<p>&#x1f538; \u65e7\u8d44\u6599\u91cc\u8fd8\u53ef\u80fd\u770b\u5230 Monitor \u7c7b\u578b&#xff08;wait\/notify \u5199\u5728\u5bf9\u8c61\u672c\u8eab\u4e0a&#xff09;&#xff0c;\u5b83\u5728 1.2.0 \u5df2\u5e9f\u5f03&#xff0c;\u7f16\u8bd1\u544a\u8b66&#xff1a;warning: class &#039;Monitor&#039; is deprecated. Use &#039;public interface Condition&#039; instead.\u3002\u65b0\u4ee3\u7801\u7edf\u4e00\u7528\u7b2c\u516d\u8282\u7684 Mutex &#043; Condition \u5199\u6cd5\u3002<\/p>\n<hr \/>\n<h3>\u4e5d\u3001CIDE \u5b9e\u64cd&#xff1a;\u8fde\u8dd1\u4e09\u6b21&#xff0c;\u4e09\u4e2a 100000<\/h3>\n<p>\u5728 CIDE \u91cc cjpm init &#8211;name syncfix \u65b0\u5efa\u5de5\u7a0b&#xff0c;\u628a\u7b2c\u4e09\u8282&#034;\u65b9\u6848\u4e00&#034;\u7684\u5b8c\u6574\u4ee3\u7801\u8d34\u8fdb src\/main.cj&#xff0c;\u70b9\u8fd0\u884c&#xff0c;\u7136\u540e\u8fde\u6309\u4e09\u6b21\u8fd0\u884c&#xff1a;<\/p>\n<p>\u671f\u671b 100000&#xff0c;\u5b9e\u9645 100000<\/p>\n<p>\u671f\u671b 100000&#xff0c;\u5b9e\u9645 100000<\/p>\n<p>\u671f\u671b 100000&#xff0c;\u5b9e\u9645 100000<\/p>\n<p>\u4e09\u6b21\u4e00\u6a21\u4e00\u6837\u3002\u518d\u7ffb\u51fa\u4e0a\u8282\u8bfe\u7b2c 26 \u8bfe\u7b2c\u4e03\u8282\u90a3\u4e2a\u6ca1\u52a0\u9501\u7684 CounterBox \u5bf9\u7167\u7740\u8dd1\u4e09\u6b21\u2014\u201433017\u300133874 \u4e4b\u7c7b\u7684\u4e71\u6570 vs \u4e09\u4e2a 100000&#xff0c;\u8fd9\u5c31\u662f&#034;\u6709\u6ca1\u6709\u540c\u6b65&#034;\u6700\u76f4\u89c2\u7684\u5bf9\u6bd4\u3002<\/p>\n<p>\u518d\u505a\u4e00\u4e2a\u7834\u574f\u5b9e\u9a8c&#xff08;\u8bb0\u5f97\u6539\u56de\u6765&#xff09;&#xff1a;\u628a addOne() \u91cc\u7684 synchronized (lock) { &#8230; } \u5220\u6389\u82b1\u62ec\u53f7\u91cc\u7684\u9501\u3001\u53d8\u56de\u88f8 count &#043;&#061; 1&#xff0c;\u8fd0\u884c&#xff0c;\u6570\u5b57\u7acb\u523b\u5f00\u59cb\u4e71\u8df3\u3002\u52a0\u9501\u7684\u4ee3\u7801\u54ea\u91cc\u90fd\u6ca1\u574f&#xff0c;\u53bb\u6389\u9501\u624d\u574f\u2014\u2014\u5e76\u53d1 Bug \u4e0d\u4f1a\u5728\u4f60\u5199\u4ee3\u7801\u65f6\u62a5\u9519&#xff0c;\u53ea\u4f1a\u5728\u8fd0\u884c\u7ed3\u679c\u91cc\u6084\u6084\u9519\u3002<\/p>\n<hr \/>\n<h3>\u5341\u3001\u5e38\u7528 API \u901f\u67e5<\/h3>\n<table>\n<tr>\u529f\u80fd\u5199\u6cd5\u5907\u6ce8<\/tr>\n<tbody>\n<tr>\n<td>\u5bfc\u5165\u540c\u6b65\u5305<\/td>\n<td>import std.sync.*<\/td>\n<td>\u672c\u8bfe\u7c7b\u578b\u5168\u5728 std.sync<\/td>\n<\/tr>\n<tr>\n<td>\u4e92\u65a5\u9501<\/td>\n<td>Mutex()<\/td>\n<td>1.2.0 \u53ef\u91cd\u5165&#xff1b;ReentrantMutex \u5df2\u5e9f\u5f03<\/td>\n<\/tr>\n<tr>\n<td>\u540c\u6b65\u5757<\/td>\n<td>synchronized (lock) { &#8230; }<\/td>\n<td>\u5757\u7ed3\u675f\u81ea\u52a8\u653e\u9501&#xff0c;\u5f02\u5e38\u4e5f\u653e<\/td>\n<\/tr>\n<tr>\n<td>\u624b\u52a8\u52a0\/\u653e\u9501<\/td>\n<td>lock.lock() \/ lock.unlock()<\/td>\n<td>\u5fc5\u987b\u6210\u5bf9&#xff0c;\u4f18\u5148\u7528 synchronized<\/td>\n<\/tr>\n<tr>\n<td>\u5c1d\u8bd5\u52a0\u9501<\/td>\n<td>lock.tryLock()<\/td>\n<td>\u8fd4\u56de Bool&#xff0c;\u62ff\u4e0d\u5230\u4e0d\u7b49<\/td>\n<\/tr>\n<tr>\n<td>\u521b\u5efa\u6761\u4ef6\u53d8\u91cf<\/td>\n<td>lock.condition()<\/td>\n<td>\u8c03\u7528\u65f6\u5fc5\u987b\u5df2\u6301\u9501&#xff0c;\u7c7b\u578b\u5199 Condition<\/td>\n<\/tr>\n<tr>\n<td>\u7b49\u5f85<\/td>\n<td>cond.wait()<\/td>\n<td>\u5fc5\u987b\u5728 synchronized \u91cc&#xff0c;\u4e14\u653e\u5728 while \u4e2d<\/td>\n<\/tr>\n<tr>\n<td>\u9650\u65f6\u7b49\u5f85<\/td>\n<td>cond.wait(timeout: Duration.second * 1)<\/td>\n<td>\u901a\u77e5\u8fd4\u56de true&#xff0c;\u8d85\u65f6\u8fd4\u56de false<\/td>\n<\/tr>\n<tr>\n<td>\u901a\u77e5<\/td>\n<td>cond.notify() \/ cond.notifyAll()<\/td>\n<td>\u5524\u9192\u4e00\u4e2a \/ \u5168\u90e8\u7b49\u5f85\u8005<\/td>\n<\/tr>\n<tr>\n<td>\u539f\u5b50\u6574\u6570<\/td>\n<td>AtomicInt64(0)<\/td>\n<td>\u53e6\u6709 8\/16\/32 \u4f4d\u53ca\u65e0\u7b26\u53f7\u7248\u672c<\/td>\n<\/tr>\n<tr>\n<td>\u539f\u5b50\u5e03\u5c14<\/td>\n<td>AtomicBool(false)<\/td>\n<td>load() \/ store() \/ compareAndSwap()<\/td>\n<\/tr>\n<tr>\n<td>\u539f\u5b50\u81ea\u589e<\/td>\n<td>a.fetchAdd(1)<\/td>\n<td>\u8fd4\u56de\u65e7\u503c&#xff1b;\u8bfb\u65b0\u503c\u7528 load()<\/td>\n<\/tr>\n<tr>\n<td>\u6bd4\u8f83\u4ea4\u6362<\/td>\n<td>a.compareAndSwap(expect, new)<\/td>\n<td>\u76f8\u7b49\u624d\u6362&#xff0c;\u8fd4\u56de\u662f\u5426\u6210\u529f<\/td>\n<\/tr>\n<tr>\n<td>\u4fe1\u53f7\u91cf<\/td>\n<td>Semaphore(n)<\/td>\n<td>acquire() \/ tryAcquire() \/ release()<\/td>\n<\/tr>\n<tr>\n<td>\u6805\u680f<\/td>\n<td>Barrier(n)<\/td>\n<td>n \u4e2a\u7ebf\u7a0b\u90fd wait() \u540e\u4e00\u8d77\u653e\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u8bfb\u5199\u9501<\/td>\n<td>ReadWriteLock()<\/td>\n<td>.readLock.lock()\u3001.writeLock.lock() \u914d\u5bf9 unlock<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u5341\u4e00\u3001\u5e38\u89c1\u95ee\u9898 FAQ<\/h3>\n<p>Q1&#xff1a;\u4e3a\u4ec0\u4e48\u7f16\u8bd1\u62a5 error: undeclared identifier &#039;Mutex&#039;&#xff1f;<\/p>\n<p>\u6ca1\u5199 import std.sync.*\u3002spawn\u3001sleep \u8fd9\u4e9b\u5728 std.core \u4e0d\u7528\u5bfc&#xff0c;\u4f46\u9501\u3001\u539f\u5b50\u7c7b\u578b\u3001\u4fe1\u53f7\u91cf\u90fd\u5728 std.sync&#xff0c;\u5fc5\u987b\u663e\u5f0f\u5bfc\u5165\u3002<\/p>\n<p>Q2&#xff1a;synchronized \u5757\u548c\u624b\u52a8 lock\/unlock \u7528\u54ea\u4e2a&#xff1f;<\/p>\n<p>\u4e00\u5f8b\u7528 synchronized\u3002\u5b83\u5728\u5757\u7ed3\u675f\u65f6&#xff08;\u5305\u62ec\u5f02\u5e38\u8df3\u51fa\u65f6&#xff09;\u81ea\u52a8\u653e\u9501&#xff0c;\u4e0d\u4f1a\u5fd8\u8bb0&#xff1b;\u624b\u52a8 unlock \u53ea\u5728\u521b\u5efa\u6761\u4ef6\u53d8\u91cf\u8fd9\u7c7b\u7279\u6b8a\u573a\u666f\u4e0b\u7528\u3002<\/p>\n<p>Q3&#xff1a;lock.condition() \u4e3a\u4ec0\u4e48\u62a5 IllegalSynchronizationStateException&#xff1f;<\/p>\n<p>\u6761\u4ef6\u53d8\u91cf\u5fc5\u987b\u7531&#034;\u5f53\u524d\u6b63\u6301\u9501\u7684\u7ebf\u7a0b&#034;\u521b\u5efa\u3002\u7167\u7b2c\u516d\u8282\u7684\u56fa\u5b9a\u5199\u6cd5&#xff1a;\u5148 lock.lock()&#xff0c;\u518d let cond &#061; lock.condition()&#xff0c;\u7136\u540e lock.unlock()&#xff0c;\u4e4b\u540e\u628a cond \u5206\u4eab\u7ed9\u5404\u7ebf\u7a0b\u4f7f\u7528\u3002<\/p>\n<p>Q4&#xff1a;1.2.0 \u771f\u7684\u6ca1\u6709 Channel \u5417&#xff1f;\u6211\u770b\u7f51\u4e0a\u6587\u7ae0\u90fd\u5728\u7528\u3002<\/p>\n<p>\u4ee5\u672c\u673a SDK \u5b9e\u6d4b\u4e3a\u51c6&#xff1a;\u5199 Channel&lt;Int64&gt;() \u4f1a\u5f97\u5230 error: undeclared identifier &#039;Channel&#039;\u30021.2.0 \u7684 std.sync \u53ea\u63d0\u4f9b\u9501\u3001\u6761\u4ef6\u53d8\u91cf\u3001\u539f\u5b50\u7c7b\u578b\u3001\u4fe1\u53f7\u91cf\u3001\u6805\u680f\u3001\u8bfb\u5199\u9501\u7b49\u3002\u7b2c\u4e03\u8282\u5df2\u7ecf\u7528\u8fd9\u4e9b\u539f\u8bed\u5b9e\u73b0\u4e86\u901a\u9053\u6700\u6838\u5fc3\u7684\u963b\u585e\u961f\u5217&#xff1b;\u5b98\u65b9 Channel \u8bf7\u5173\u6ce8\u540e\u7eed SDK \u7248\u672c\u3002<\/p>\n<p>Q5&#xff1a;\u539f\u5b50\u53d8\u91cf\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u76f4\u63a5\u8bfb\u5199 a.value&#xff1f;<\/p>\n<p>\u539f\u5b50\u7c7b\u578b\u6ca1\u6709\u516c\u5f00\u7684 value \u5b57\u6bb5&#xff08;\u62a5 error: can not access field &#039;value&#039;&#xff09;\u3002\u8bfb\u7528 load()\u3001\u5199\u7528 store()&#xff0c;\u6240\u6709\u8bbf\u95ee\u90fd\u8d70\u539f\u5b50\u65b9\u6cd5&#xff0c;\u624d\u80fd\u4fdd\u8bc1\u5e76\u53d1\u5b89\u5168\u3002<\/p>\n<p>Q6&#xff1a;wait() \u4e3a\u4ec0\u4e48\u5fc5\u987b\u5199\u5728 while \u91cc&#xff0c;if \u4e0d\u884c\u5417&#xff1f;<\/p>\n<p>\u7ebf\u7a0b\u4ece wait() \u9192\u6765\u65f6\u6761\u4ef6\u672a\u5fc5\u4ecd\u6210\u7acb&#xff08;\u53ef\u80fd\u88ab\u5176\u4ed6\u7ebf\u7a0b\u62a2\u5148\u6539\u53d8&#xff0c;\u6216\u51fa\u73b0\u865a\u5047\u5524\u9192&#xff09;\u3002while \u4f1a\u5728\u9192\u6765\u540e\u91cd\u65b0\u68c0\u67e5\u4e00\u6b21\u6761\u4ef6&#xff0c;\u4e0d\u6ee1\u8db3\u5c31\u7ee7\u7eed\u7b49&#xff1b;if \u53ea\u68c0\u67e5\u4e00\u6b21&#xff0c;\u9192\u6765\u5c31\u786c\u7740\u5934\u76ae\u5f80\u4e0b\u8d70&#xff0c;\u5bb9\u6613\u51fa\u9519\u3002\u8fd9\u662f\u6761\u4ef6\u53d8\u91cf\u7684\u6807\u51c6\u5199\u6cd5&#xff0c;\u7167\u6284\u5373\u53ef\u3002<\/p>\n<hr \/>\n<h3>\u5341\u4e8c\u3001\u8bfe\u540e\u7ec3\u4e60<\/h3>\n<li>&#xff08;\u5fc5\u505a&#xff09;\u7528\u9501\u4fdd\u62a4\u4e00\u4e2a&#034;\u5750\u6807\u70b9&#034;&#xff1a;x\u3001y \u4e24\u4e2a\u5b57\u6bb5\u5fc5\u987b\u4e00\u8d77\u79fb\u52a8&#xff08;\u8fd9\u7c7b\u591a\u5b57\u6bb5\u590d\u5408\u64cd\u4f5c\u539f\u5b50\u7c7b\u578b\u7ba1\u4e0d\u4e86&#xff0c;\u53ea\u80fd\u7528\u9501&#xff09;\u3002\u628a\u4e0b\u9762\u7a0b\u5e8f\u7684 move \u65b9\u6cd5\u8865\u5b8c\u6574&#xff0c;\u7136\u540e\u8d77 10 \u4e2a\u7ebf\u7a0b\u5404\u8c03\u7528 move(1) 1000 \u6b21\u3002\u9700\u8981 import std.sync.* \u548c import std.collection.ArrayList\u3002\u671f\u671b\u8f93\u51fa&#xff1a;x &#061; 10000&#xff0c;y &#061; 10000\u3002<\/li>\n<p>class Position {<br \/>\n    let lock &#061; Mutex()<br \/>\n    var x: Int64 &#061; 0<br \/>\n    var y: Int64 &#061; 0<\/p>\n<p>    func move(step: Int64) {<br \/>\n        \/\/ TODO&#xff1a;\u7528 synchronized (lock) \u628a x\u3001y \u540c\u65f6\u52a0\u4e0a step<br \/>\n    }<br \/>\n}<br \/>\n\/\/ main&#xff1a;10 \u4e2a spawn&#xff0c;\u6bcf\u4e2a\u5faa\u73af 1000 \u6b21\u8c03\u7528 p.move(1)&#xff1b;<br \/>\n\/\/ \u5168\u90e8 get() \u540e\u6253\u5370 println(&#034;x &#061; ${p.x}&#xff0c;y &#061; ${p.y}&#034;)<\/p>\n<li>&#xff08;\u5fc5\u505a&#xff09;\u7528 compareAndSwap \u5b9e\u73b0&#034;\u4e00\u6b21\u6027\u521d\u59cb\u5316&#034;&#xff1a;5 \u4e2a\u7ebf\u7a0b\u540c\u65f6\u53bb\u62a2&#xff0c;\u6700\u591a\u53ea\u80fd\u6709\u4e00\u4e2a\u6210\u529f\u3002\u51fd\u6570\u7b7e\u540d\u5df2\u7ecf\u7ed9\u597d&#xff0c;main \u91cc\u8d77 5 \u4e2a\u7ebf\u7a0b&#xff08;\u8fdb\u5165\u540e\u5148 sleep(Duration.millisecond * 100) \u8ba9\u5927\u5bb6\u5c3d\u91cf\u540c\u65f6&#xff09;&#xff0c;\u628a\u6bcf\u4e2a Future&lt;Bool&gt; \u7684\u7ed3\u679c\u5728\u4e3b\u7ebf\u7a0b get() \u56de\u6765\u6570 true \u7684\u4e2a\u6570\u3002\u671f\u671b\u8f93\u51fa&#xff1a;\u6210\u529f\u521d\u59cb\u5316\u7684\u7ebf\u7a0b\u6570&#xff1a;1\u3002<\/li>\n<p>import std.sync.*<br \/>\n\/\/ func tryInit(flag: AtomicInt64): Bool { return flag.compareAndSwap(0, 1) }<br \/>\n\/\/ \u63d0\u793a&#xff1a;main \u91cc let flag &#061; AtomicInt64(0)&#xff0c;\u628a flag \u4f20\u8fdb\u6bcf\u4e2a spawn<\/p>\n<li>&#xff08;\u5fc5\u505a&#xff09;\u201c\u5f00\u95e8\u4ee4\u201d&#xff1a;\u5de5\u4f5c\u7ebf\u7a0b\u5148\u6253\u5370 \u7b49\u5f85\u5f00\u95e8&#xff0c;\u7136\u540e\u5728\u6761\u4ef6\u53d8\u91cf\u4e0a\u7b49\u5f85&#xff1b;\u4e3b\u7ebf\u7a0b\u7761 200 \u6beb\u79d2\u540e\u6253\u5370 \u5f00\u95e8 \u5e76\u901a\u77e5\u5b83&#xff1b;\u5de5\u4f5c\u7ebf\u7a0b\u88ab\u5524\u9192\u540e\u6253\u5370 \u5f00\u59cb\u5e72\u6d3b\u3002\u8bf7\u8865\u5168\u4e0b\u9762\u9aa8\u67b6\u4e2d\u7684\u4e09\u5904 TODO&#xff08;\u63d0\u793a&#xff1a;\u521b\u5efa\u6761\u4ef6\u53d8\u91cf\u7684\u56fa\u5b9a\u5199\u6cd5\u89c1\u7b2c\u516d\u8282&#xff0c;\u7b49\u5f85\u548c\u901a\u77e5\u90fd\u8981\u5305\u5728 synchronized (lock) \u91cc&#xff09;\u3002\u671f\u671b\u8f93\u51fa\u4e25\u683c\u6309\u4e0b\u9762\u4e09\u884c\u987a\u5e8f\u51fa\u73b0&#xff1a;<\/li>\n<p>\u7b49\u5f85\u5f00\u95e8<br \/>\n\u5f00\u95e8<br \/>\n\u5f00\u59cb\u5e72\u6d3b<\/p>\n<p>let lock &#061; Mutex()<br \/>\n\/\/ TODO&#xff1a;lock.lock() \u2192 let cond &#061; lock.condition() \u2192 lock.unlock()<br \/>\nlet worker &#061; spawn {<br \/>\n    synchronized (lock) {<br \/>\n        println(&#034;\u7b49\u5f85\u5f00\u95e8&#034;)<br \/>\n        \/\/ TODO&#xff1a;cond.wait()<br \/>\n        println(&#034;\u5f00\u59cb\u5e72\u6d3b&#034;)<br \/>\n    }<br \/>\n}<br \/>\nsleep(Duration.millisecond * 200)<br \/>\nsynchronized (lock) {<br \/>\n    println(&#034;\u5f00\u95e8&#034;)<br \/>\n    \/\/ TODO&#xff1a;cond.notify()<br \/>\n}<br \/>\nworker.get()<\/p>\n<li>&#xff08;\u9009\u505a&#xff09;\u7528 Semaphore(2) \u6a21\u62df&#034;\u53ea\u6709 2 \u4e2a\u4f4d\u7684\u66f4\u8863\u5ba4&#034;&#xff1a;6 \u4e2a\u4eba&#xff08;\u7ebf\u7a0b&#xff09;\u8fdb\u573a&#xff0c;\u6bcf\u4eba\u8fdb\u53bb\u540e\u505c\u7559 sleep(Duration.millisecond * 100) \u518d\u51fa\u6765\u3002\u7528\u4e00\u4e2a\u5e26 Mutex \u7684\u88c5\u7bb1\u7c7b\u7edf\u8ba1&#034;\u540c\u65f6\u5728\u573a\u4eba\u6570&#034;\u7684\u5cf0\u503c&#xff08;\u6ce8\u610f&#xff1a;\u8ba1\u6570\u53d8\u91cf\u662f var&#xff0c;\u4e0d\u80fd\u76f4\u63a5\u88ab spawn \u6355\u83b7&#xff0c;\u8981\u50cf\u7b2c 26 \u8bfe\u90a3\u6837\u88c5\u8fdb class&#xff09;\u3002\u671f\u671b\u8f93\u51fa&#xff1a;\u540c\u65f6\u5728\u66f4\u8863\u5ba4\u7684\u5cf0\u503c\u4eba\u6570&#xff1a;2\u3002<\/li>\n<hr \/>\n<h3>\u4e0b\u8282\u9884\u544a<\/h3>\n<p>\u672c\u8bfe\u628a&#034;\u7ebf\u7a0b\u4e4b\u95f4\u5982\u4f55\u5b89\u5168\u5730\u534f\u4f5c&#034;\u8bb2\u5b8c\u4e86&#xff1a;\u9501\u9632\u62a2\u3001\u539f\u5b50\u7c7b\u578b\u9632\u4e22\u6570\u3001\u6761\u4ef6\u53d8\u91cf\u9632\u5fd9\u7b49\u3001\u963b\u585e\u961f\u5217\u8d1f\u8d23\u4f20\u8bdd\u3002\u7b2c 28 \u8bfe \u5e76\u53d1\u5b9e\u6218&#xff1a;\u591a\u7ebf\u7a0b\u4efb\u52a1\u5904\u7406 \u628a\u8fd9\u4e9b\u5bb6\u4f19\u62c9\u5230\u771f\u6b63\u7684\u4e1a\u52a1\u573a\u666f\u91cc\u905b\u4e00\u905b&#xff1a;\u4e00\u6279\u4efb\u52a1\u600e\u4e48\u6d3e\u7ed9\u591a\u4e2a\u5de5\u4f5c\u7ebf\u7a0b\u5e76\u53d1\u5904\u7406\u3001\u5904\u7406\u7ed3\u679c\u600e\u4e48\u6309\u987a\u5e8f\u56de\u6536\u3001\u751f\u4ea7\u8fc7\u5feb\u6d88\u8d39\u8fc7\u6162\u65f6\u600e\u4e48\u7528\u963b\u585e\u961f\u5217\u524a\u5cf0\u586b\u8c37\u3002\u4e09\u8282\u8bfe\u7684\u5e76\u53d1\u77e5\u8bc6\u4f1a\u5728\u90a3\u4e00\u8bfe\u4e32\u6210\u4e00\u6761\u7ebf\u3002<\/p>\n<hr \/>\n<p>\u7cfb\u5217\u8bf4\u660e&#xff1a;\u672c\u7cfb\u5217\u57fa\u4e8e Windows \u5e73\u53f0 &#043; CIDE &#043; \u4ed3\u9889 SDK&#xff08;1.2.0&#xff09;\u7f16\u5199&#xff0c;\u6240\u6709\u4ee3\u7801\u5747\u5df2\u5b9e\u9645\u7f16\u8bd1\u8fd0\u884c\u901a\u8fc7\u3002\u5982\u9047 SDK \u7248\u672c\u5dee\u5f02\u5bfc\u81f4\u7684\u7ec6\u8282\u51fa\u5165&#xff0c;\u4ee5\u4f60\u672c\u5730\u7248\u672c\u4e3a\u51c6&#xff0c;\u6b22\u8fce\u8bc4\u8bba\u533a\u4ea4\u6d41\u3002<\/p>\n<hr \/>\n<h3>&#x1f4ac; \u9047\u5230\u95ee\u9898&#xff1f;\u626b\u7801\u8054\u7cfb\u4f5c\u8005<\/h3>\n<p>\u8ddf\u7740\u8bfe\u7a0b\u7ec3\u4e60\u65f6&#xff0c;\u5982\u679c\u5728 SDK \u5b89\u88c5\u3001\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u3001\u7f16\u8bd1\u62a5\u9519\u6216\u8c03\u8bd5\u4e0a\u5361\u4f4f&#xff0c;\u6b22\u8fce\u626b\u7801\u52a0\u4f5c\u8005\u4f01\u4e1a\u5fae\u4fe1\u76f4\u63a5\u54a8\u8be2&#xff08;\u8bf7\u5907\u6ce8&#034;\u4ed3\u9889\u8bfe\u7a0b&#034;&#xff09;&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261006034101-6ac46dcdce649.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u79bb\u7ebf\u73af\u5883\u4e0b\u56fe\u7247\u53ef\u80fd\u52a0\u8f7d\u4e0d\u51fa\u6765&#xff0c;\u4e5f\u53ef\u4ee5\u5728 CIDE \u83dc\u5355 Help \u25b8 \u8054\u7cfb\u4f5c\u8005 \/ Contact \u4e2d\u67e5\u770b\u540c\u4e00\u5f20\u4e8c\u7ef4\u7801&#xff08;\u5e94\u7528\u5185\u7f6e\u515c\u5e95\u56fe&#xff0c;\u65e0\u9700\u8054\u7f51&#xff09;\u3002<\/p>\n<hr \/>\n<h3>&#x1f4e5; \u5de5\u5177\u4e0b\u8f7d<\/h3>\n<p>\u672c\u7cfb\u5217\u5168\u7a0b\u4f7f\u7528\u7684\u4ed3\u9889 IDE \u2014\u2014 CIDE&#xff08;\u514d\u8d39\u5f00\u6e90\u3001\u793e\u533a\u7248&#xff09;&#xff1a;<\/p>\n<ul>\n<li>GitCode \u4ed3\u5e93 \/ \u5b89\u88c5\u5305\u4e0b\u8f7d&#xff1a;https:\/\/gitcode.com\/wp_upala\/cide<\/li>\n<li>\u6253\u5f00\u9875\u9762\u540e\u8fdb\u5165 \u53d1\u884c\u7248&#xff08;Releases&#xff09;&#xff0c;\u4e24\u79cd\u5305\u4efb\u9009\u5176\u4e00&#xff1a;\n<ul>\n<li>\u5b89\u88c5\u7248&#xff1a;\u4e0b\u8f7d CIDE-&lt;\u7248\u672c&gt;-x64-Setup.exe&#xff0c;\u53cc\u51fb\u5b89\u88c5&#xff0c;\u9002\u5408\u65e5\u5e38\u957f\u671f\u4f7f\u7528&#xff1b;<\/li>\n<li>\u514d\u5b89\u88c5\u7248&#xff08;Portable&#xff09;&#xff1a;\u4e0b\u8f7d CIDE-&lt;\u7248\u672c&gt;-x64-Portable.zip&#xff0c;\u89e3\u538b\u5230\u4efb\u610f\u76ee\u5f55\u5373\u7528&#xff0c;\u4e0d\u5199\u6ce8\u518c\u8868\u3001\u4e0d\u7559\u5b89\u88c5\u75d5\u8ff9&#xff0c;\u62f7\u5230 U \u76d8\u4e5f\u80fd\u5728\u522b\u7684\u7535\u8111\u76f4\u63a5\u8fd0\u884c&#xff08;\u5305\u5185\u9644\u300a\u4f7f\u7528\u8bf4\u660e.txt\u300b&#xff09;\u3002\u9002\u5408\u5148\u8bd5\u7528\u3001\u6216\u5728\u53d7\u9650\u7535\u8111\u4e0a\u5b66\u4e60\u672c\u7cfb\u5217\u8bfe\u7a0b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u4ed3\u9889 SDK \u8bf7\u524d\u5f80\u4ed3\u9889\u7f16\u7a0b\u8bed\u8a00\u5b98\u7f51\u4e0b\u8f7d&#xff1a;https:\/\/cangjie-lang.cn<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c 27 \u8bfe \u7ebf\u7a0b\u540c\u6b65&#xff1a;\u4e92\u65a5\u9501\u3001\u539f\u5b50\u7c7b\u578b\u4e0e\u6761\u4ef6\u53d8\u91cf \u4e0a\u8282\u8bfe\u7ed3\u5c3e\u7684 CounterBox \u60e8\u6848\u8fd8\u60ac\u7740&#xff1a;10 \u4e2a\u7ebf\u7a0b\u5404\u52a0 10000 \u6b21&#xff0c;\u671f\u671b 100000&#xff0c;\u5b9e\u9645\u53ea\u6709 33017\u300133874\u2026\u2026\u6bcf\u6b21\u8dd1\u6570\u5b57\u8fd8\u90fd\u4e0d\u4e00\u6837\u3002\u672c\u8bfe\u5c31\u6765\u7b97\u8d26&#xff1a;\u7528 Mutex \u4e92\u65a5\u9501\u628a\\&#8221;\u8bfb\u2014\u52a0\u2014\u5199\\&#8221;\u4e09\u6b65\u5408\u6210\u4e00\u6b65&#xff0c;\u7528 Atomic \u539f\u5b50\u7c7b\u578b\u8ba9\u81ea\u589e\u672c\u8eab\u4e0d\u53ef\u5206\u5272&#xff0c;\u518d\u7528 Condition \u6761\u4ef6\u53d8\u91cf\u89e3\u51b3\\&#8221;\u7ebf\u7a0b\u4e4b\u95f4\u4f60\u7b49\u6211\u3001\u6211<\/p>\n","protected":false},"author":2,"featured_media":113438,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[70,190,227],"topic":[],"class_list":["post-113439","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-ide","tag-190","tag-227"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u4ed3\u9889\u8bed\u8a00\u5165\u95e8 \u00b7 \u7b2c27\u8bfe\u3011 - \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\/113439.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u4ed3\u9889\u8bed\u8a00\u5165\u95e8 \u00b7 \u7b2c27\u8bfe\u3011 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7b2c 27 \u8bfe \u7ebf\u7a0b\u540c\u6b65&#xff1a;\u4e92\u65a5\u9501\u3001\u539f\u5b50\u7c7b\u578b\u4e0e\u6761\u4ef6\u53d8\u91cf \u4e0a\u8282\u8bfe\u7ed3\u5c3e\u7684 CounterBox \u60e8\u6848\u8fd8\u60ac\u7740&#xff1a;10 \u4e2a\u7ebf\u7a0b\u5404\u52a0 10000 \u6b21&#xff0c;\u671f\u671b 100000&#xff0c;\u5b9e\u9645\u53ea\u6709 33017\u300133874\u2026\u2026\u6bcf\u6b21\u8dd1\u6570\u5b57\u8fd8\u90fd\u4e0d\u4e00\u6837\u3002\u672c\u8bfe\u5c31\u6765\u7b97\u8d26&#xff1a;\u7528 Mutex \u4e92\u65a5\u9501\u628a&quot;\u8bfb\u2014\u52a0\u2014\u5199&quot;\u4e09\u6b65\u5408\u6210\u4e00\u6b65&#xff0c;\u7528 Atomic \u539f\u5b50\u7c7b\u578b\u8ba9\u81ea\u589e\u672c\u8eab\u4e0d\u53ef\u5206\u5272&#xff0c;\u518d\u7528 Condition \u6761\u4ef6\u53d8\u91cf\u89e3\u51b3&quot;\u7ebf\u7a0b\u4e4b\u95f4\u4f60\u7b49\u6211\u3001\u6211\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/113439.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-06T03:41:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261006034101-6ac46dcdce649.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=\"10 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/113439.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/113439.html\",\"name\":\"\u3010\u4ed3\u9889\u8bed\u8a00\u5165\u95e8 \u00b7 \u7b2c27\u8bfe\u3011 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-06T03:41:03+00:00\",\"dateModified\":\"2026-10-06T03:41:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/113439.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/113439.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/113439.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u4ed3\u9889\u8bed\u8a00\u5165\u95e8 \u00b7 \u7b2c27\u8bfe\u3011\"}]},{\"@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\u4ed3\u9889\u8bed\u8a00\u5165\u95e8 \u00b7 \u7b2c27\u8bfe\u3011 - \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\/113439.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u4ed3\u9889\u8bed\u8a00\u5165\u95e8 \u00b7 \u7b2c27\u8bfe\u3011 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7b2c 27 \u8bfe \u7ebf\u7a0b\u540c\u6b65&#xff1a;\u4e92\u65a5\u9501\u3001\u539f\u5b50\u7c7b\u578b\u4e0e\u6761\u4ef6\u53d8\u91cf \u4e0a\u8282\u8bfe\u7ed3\u5c3e\u7684 CounterBox \u60e8\u6848\u8fd8\u60ac\u7740&#xff1a;10 \u4e2a\u7ebf\u7a0b\u5404\u52a0 10000 \u6b21&#xff0c;\u671f\u671b 100000&#xff0c;\u5b9e\u9645\u53ea\u6709 33017\u300133874\u2026\u2026\u6bcf\u6b21\u8dd1\u6570\u5b57\u8fd8\u90fd\u4e0d\u4e00\u6837\u3002\u672c\u8bfe\u5c31\u6765\u7b97\u8d26&#xff1a;\u7528 Mutex \u4e92\u65a5\u9501\u628a\"\u8bfb\u2014\u52a0\u2014\u5199\"\u4e09\u6b65\u5408\u6210\u4e00\u6b65&#xff0c;\u7528 Atomic \u539f\u5b50\u7c7b\u578b\u8ba9\u81ea\u589e\u672c\u8eab\u4e0d\u53ef\u5206\u5272&#xff0c;\u518d\u7528 Condition \u6761\u4ef6\u53d8\u91cf\u89e3\u51b3\"\u7ebf\u7a0b\u4e4b\u95f4\u4f60\u7b49\u6211\u3001\u6211","og_url":"https:\/\/www.wsisp.com\/helps\/113439.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-06T03:41:03+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261006034101-6ac46dcdce649.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"10 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/113439.html","url":"https:\/\/www.wsisp.com\/helps\/113439.html","name":"\u3010\u4ed3\u9889\u8bed\u8a00\u5165\u95e8 \u00b7 \u7b2c27\u8bfe\u3011 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-06T03:41:03+00:00","dateModified":"2026-10-06T03:41:03+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/113439.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/113439.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/113439.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u4ed3\u9889\u8bed\u8a00\u5165\u95e8 \u00b7 \u7b2c27\u8bfe\u3011"}]},{"@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\/113439","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=113439"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/113439\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/113438"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=113439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=113439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=113439"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=113439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}