{"id":428303,"date":"2021-04-18T06:46:54","date_gmt":"2021-04-17T22:46:54","guid":{"rendered":"http:\/\/4563.org\/?p=428303"},"modified":"2021-04-18T06:46:54","modified_gmt":"2021-04-17T22:46:54","slug":"%e5%88%9a%e5%ad%a6%e5%a4%9a%e7%ba%bf%e7%a8%8b%ef%bc%8c%e8%af%b7%e9%97%ae%e4%b8%8b%e9%9d%a2%e8%bf%99%e6%ae%b5%e7%a8%8b%e5%ba%8f%e4%b8%ba%e4%bb%80%e4%b9%88%e5%81%9c%e4%b8%8d%e4%b8%8b%e6%9d%a5%e5%95%8a","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=428303","title":{"rendered":"\u521a\u5b66\u591a\u7ebf\u7a0b\uff0c\u8bf7\u95ee\u4e0b\u9762\u8fd9\u6bb5\u7a0b\u5e8f\u4e3a\u4ec0\u4e48\u505c\u4e0d\u4e0b\u6765\u554a\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u521a\u5b66\u591a\u7ebf\u7a0b\uff0c\u8bf7\u95ee\u4e0b\u9762\u8fd9\u6bb5\u7a0b\u5e8f\u4e3a\u4ec0\u4e48\u505c\u4e0d\u4e0b\u6765\u554a\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Frankhong <\/span>  <span><i><\/i> 9<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e66\u4e0a\u8bf4\u7684\u4e0d\u662f\u5f88\u6e05\u695a\uff0c\u53ea\u8bf4\u662f\u7f16\u8bd1\u5668\u4f18\u5316\u7684\u7ed3\u679c\u3002\u5177\u4f53\u662f\u4ec0\u4e48\u539f\u56e0\u5462\uff1f\u7f16\u8bd1\u5668\u518d\u600e\u4e48\u4f18\u5316 ready=true \u4e0d\u8fd8\u5f97\u6267\u884c\u5417\uff0c\u600e\u4e48 while(!ready)\u5c31\u9000\u51fa\u4e0d\u4e86\u4e86\u5462\uff1f<\/p>\n<pre><code>public class NoVisibility {     private static boolean ready;       private static int number;          private static class ReaderThread extends Thread {           public void run() {               while (!ready);             System.out.println(number);           }       }         public static void main(String[] args) throws InterruptedException {           new ReaderThread().start();           Thread.sleep(1000);         number = 42;           ready = true;           Thread.sleep(10000);     }   } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>41<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5653060\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : oska874 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             while \uff08 ready \uff09\u76f4\u63a5\u4f18\u5316\u6210 while \uff08 1 \uff09\u4e86\uff0c\u6267\u884c\u7684\u65f6\u5019\u548c ready \u5df2\u7ecf\u6ca1\u5173\u7cfb\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653061\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lsry <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u56e0\u4e3a\u4f60 ready \u5728\u65b0\u5efa\u7684\u7ebf\u7a0b\u548c main \u7ebf\u7a0b\u4e2d\u5404\u6709\u4e00\u4e2a\u5907\u4efd\uff0c\u5728 main \u7ebf\u7a0b\u4e2d\u4fee\u6539 ready \u65e0\u6cd5\u4fee\u6539\u4f60\u65b0\u5efa\u7ebf\u7a0b\u7684 ready \u5907\u4efd\uff0c\u5982\u679c\u8ba9\u4f60\u65b0\u5efa\u7684\u7ebf\u7a0b\u770b\u5230 main \u4fee\u6539\u7684\u503c\uff0c\u5728\u524d\u9762\u52a0 volatile \u5373\u53ef\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653062\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : az467 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6708\u7ecf\u95ee\u9898\u3002\u3002\u3002<\/p>\n<p>\u4e0d\u662f\u7f16\u8bd1\u5668\u4f18\u5316\uff0c\u662f jvm \u4f18\u5316\u3002<\/p>\n<p>\u4f60\u6ca1\u628a jvm \u7684 jit \u5173\u6389\uff0c\u6240\u4ee5 jvm \u628a <\/p>\n<p>while (!ready); <\/p>\n<p>\u4f18\u5316\u6210\u4e86 <\/p>\n<p>if (ready == false)<br \/>while (true);                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653063\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Kasumi20 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u786e\u5b9e\u4e0d\u662f\u4e0d\u662f\u7f16\u8bd1\u5668\u4f18\u5316\uff0c\u53cd\u7f16\u8bd1\u56de\u6765\u662f\u539f\u6765\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u90a3\u7a76\u7adf\u662f 2 \u8fd8\u662f 3 \u8bf4\u7684\u5bf9\u5462                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653064\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : PythonYXY <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5efa\u8bae\u4e86\u89e3\u4e0b Java \u5185\u5b58\u6a21\u578b\uff08 JMM \uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653065\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ipwx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6ca1\u5b66\u8fc7 Java\uff0c\u4f46\u662f\u6700\u8fd1\u6211\u5199 C++\uff0c\u78b0\u5230\u8fd9\u79cd\u591a\u7ebf\u7a0b\u8bfb\u5199\u6307\u793a\u53d8\u91cf\uff0c\u6211\u90fd\u662f\u4e0a std::atomic \u7684\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653066\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : choice4 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e8c\u8bf4\u7684\u5bf9,Ready \u8981\u4fdd\u8bc1\u5185\u5b58\u53ef\u89c1\u6027                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653067\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Jooooooooo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u641c\u4e00\u4e0b jmm \u6709\u771f\u76f8.<\/p>\n<p>\u5177\u4f53\u8bf4\u548c\u591a\u6838 cpu \u770b\u4e0d\u89c1\u5176\u5b83 cpu \u7684\u503c\u6709\u5173\u7cfb<\/p>\n<p>ready=true cpu1 \u6267\u884c\u5b8c, \u6267\u884c while(!ready) \u7684 cpu2 \u770b\u4e0d\u89c1                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653068\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yitingbai <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             2 \u7684\u89e3\u51b3\u65b9\u6848\u6ca1\u95ee\u9898, \u53e6\u5916\u6211\u8bd5\u4e86\u4e00\u4e0b,while()\u4e2d\u5199\u4e00\u884c\u4ee3\u7801\u4e5f\u53ef\u4ee5\u505c, java \u641e\u4e86\u8fd9\u4e48\u4e45, \u4eca\u5929\u5b66\u5230\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653069\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ignor <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @az467 \u7eaf\u597d\u5947\uff0c\u8fd9\u79cd\u660e\u663e\u9519\u8bef\u7684\u4f18\u5316\u6709\u4ec0\u4e48\u5b58\u5728\u7684\u5fc5\u8981\u5462\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653070\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : RicardoY <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ef\u89c1\u6027 \u770b\u4e00\u4e0b Java \u5185\u5b58\u6a21\u578b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653071\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : RicardoY <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60 sleep \u4e00\u4e0b\u5176\u5b9e\u4e5f\u53ef\u4ee5 \u4f46\u662f\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48 sleep \u53ef\u4ee5 \u539f\u5b50\u53d8\u91cf \/\u52a0\u9501 \/volatile \u662f\u53ef\u4ee5\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653072\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : az467 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ignor <\/p>\n<p>\u4e86\u89e3\u4e00\u4e0b JMM\uff0c\u4f60\u5c31\u4f1a\u77e5\u9053\u8fd9\u79cd\u4f18\u5316\u975e\u4f46\u6ca1\u6709\u9519\u8bef\uff0c\u53cd\u800c\u5b8c\u5168\u662f\u6b63\u786e\u7684\u3002<\/p>\n<p>\u56e0\u4e3a\u53d8\u91cf\u6ca1\u6709\u88ab volatile \u4fee\u9970\uff0c\u6240\u4ee5 jvm \u4e0d\u7528\u4fdd\u8bc1\u53d8\u91cf\u5728\u7ebf\u7a0b\u95f4\u7684\u53ef\u89c1\u6027\u3002<br \/>\u65e2\u7136\u4e0d\u7528\u4fdd\u8bc1\uff0c\u90a3\u5f53\u7136\u53ef\u4ee5\u5b8c\u5168\u4e0d\u4fdd\u8bc1\uff0c\u751a\u81f3\u53ef\u4ee5\u53cd\u8fc7\u6765\u201c\u4fdd\u8bc1\u201d\u53d8\u91cf\u5b8c\u5168\u4e0d\u53ef\u89c1\u3002<\/p>\n<p>\u8fd9\u5c31\u50cf\u5f88\u591a\u4eba\u5f00\u4e86 gcc \u7684 O3 \u4f18\u5316\uff0c\u7136\u540e\u60ca\u5947\u5730\u53d1\u73b0\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u679c\u8ddf\u81ea\u5df1\u9884\u671f\u4e0d\u4e00\u81f4\u3002<br \/>\u4e0d\u597d\u610f\u601d\uff0c\u662f\u4f60\u628a\u4ee3\u7801\u5199\u9519\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653073\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : brucewuio <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             volatile \u54af \u5185\u5b58\u53ef\u89c1\u6027                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653074\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ignor <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @az467 \u611f\u89c9\u8fd8\u662f\u6ca1\u592a\u7406\u89e3\u2026\u2026<br \/>\u6211\u6240\u4e86\u89e3\u5230\u7684\u53ef\u89c1\u6027\uff0c\u662f\u6307\u7ebf\u7a0b\u5bf9\u53d8\u91cf\u7684\u4fee\u6539\uff0c\u80fd\u591f\u201c\u53ca\u65f6\u5730\u201d\u88ab\u5176\u4ed6\u7ebf\u7a0b\u6240\u770b\u5230<br \/>\u6240\u4ee5 volatile \u89e3\u51b3\u7684\u5e94\u8be5\u662f\u201c\u53ca\u65f6\u5730\u201d\u7684\u95ee\u9898\uff0c\u800c\u4e0d\u662f\u201c\u80fd\u4e0d\u80fd\u201d\u7684\u95ee\u9898\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5373\u4f7f\u6ca1\u6709 volatile\uff0c\u8fd9\u79cd\u4fee\u6539\u4e5f\u5e94\u8be5\u201c\u80fd\u591f\u201d\u88ab\u89c2\u5bdf\u5230\uff0c\u53ea\u662f\u65f6\u95f4\u4e0a\u6709\u5ef6\u8fdf\u800c\u5df2\u3002\u56e0\u4e3a\u5b83\u662f\u4e2a\u53d8\u91cf\uff0c\u5e94\u8be5\u662f\u53ef\u4ee5\u88ab\u4fee\u6539\u7684\uff0c\u6240\u4ee5\u8fd9\u79cd\u201c\u80fd\u591f\u201d\u4e0d\u5e94\u8be5\u88ab\u4f18\u5316\u6389\u624d\u5bf9\u5427\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653075\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : az467 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ignor \u4f60\u53ef\u4ee5\u8fd9\u4e48\u7406\u89e3\uff0c\u201c\u65f6\u95f4\u4e0a\u7684\u5ef6\u8fdf\u201d\u5728\u8fd9\u91cc\u662f\u65e0\u7a77\u5927\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653076\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ZeawinL <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u91cc\u662f\u4e24\u4e2a\u7ebf\u7a0b\uff0c\u7ebf\u7a0b 1 \u8d4b\u503c\u540e\u5bf9\u7ebf\u7a0b 2 \u672a\u5fc5\u53ef\u89c1\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653077\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ignor <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @az467 \u8fd9\u5c31\u662f\u96be\u4ee5\u7406\u89e3\u7684\u5730\u65b9\uff0c\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u8ba4\u4e3a\u628a\u4e00\u4e2a\u6709\u9650\u7684\u65f6\u95f4\u95f4\u9694\u6539\u4e3a\u65e0\u7a77\u5927\u662f\u4e00\u79cd\u6b63\u786e\u7684\u4f18\u5316\u5462\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653078\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wwqgtxx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ignor \u56e0\u4e3a\u4f5c\u4e3a\u4f18\u5316\u5668\uff0c\u5e76\u4e0d\u80fd(\u51c6\u786e\u8bf4\u662f\u5e76\u4e0d\u4f1a\u53bb)\u9884\u6d4b\u662f\u5426\u4f1a\u6709\u5176\u4ed6\u7ebf\u7a0b\u4fee\u6539\u8be5\u53d8\u91cf\uff0c\u6240\u4ee5\u53ea\u8981\u5f53\u524d\u7ebf\u7a0b\u6ca1\u4e0d\u4f1a\u6709\u5bf9\u8be5\u53d8\u91cf\u7684\u4fee\u6539\u64cd\u4f5c\uff0c\u5c31\u80fd\u76f4\u63a5\u8ba4\u5b9a\u4e3a\u8be5\u53d8\u91cf\u4e3a\u5e38\u91cf                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653079\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : francis59 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7a7a\u5faa\u73af\u88ab JIT \u4f18\u5316\u4e86\uff0c\u7981\u7528 JIT \u5c31\u884c\uff0c\u52a0 JVM \u53c2\u6570-Xint\uff0c\u5728\u89e3\u91ca\u6a21\u5f0f\u8fd0\u884c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653080\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : francis59 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             -Xint<br \/> Operate in interpreted-only mode. Compilation to native code is disabled, and all bytecodes are executed by the interpreter. The performance benefits offered by the Java HotSpot Client VM&#8217;s adaptive compiler will not be present in this mode.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653081\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : iseki <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u5728\u90a3\u4e2a while \u91cc println \u6216\u8005\u5e72\u70b9\u5565\uff0c\u591a\u534a\u5c31\u53d1\u73b0 ready \u8d77\u4f5c\u7528\u4e86\uff0c\u6240\u4ee5\u6211\u89c9\u5f97\u4e0d\u662f jit \u4f18\u5316\u4e86 ready\uff0c\u5355\u7eaf\u7f13\u5b58\u7684\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653082\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lewis89 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @iseki \u6fc0\u8fdb\u7f16\u8bd1\u7684\u95ee\u9898\uff0c\u6211\u5df2\u7ecf\u7814\u7a76\u8fc7\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653083\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lewis89 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u662f\u865a\u62df\u673a\u7684\u6fc0\u8fdb\u7f16\u8bd1\u7684\u95ee\u9898\uff0c\u865a\u62df\u673a\u7f16\u8bd1\u7684\u65f6\u5019 \u8ba4\u4e3a ready \u662f\u4e00\u4e2a\u975e volatile \u7684 static \u53d8\u91cf\uff0c<\/p>\n<p>\u6fc0\u8fdb\u7f16\u8bd1\u540e\u7684\u6c47\u7f16\u4ee3\u7801\u5c31\u53ea\u4ece\u5806\u5185\u5b58\u91cc\u9762\u53d6\u4e86\u4e00\u6b21\u8fd9\u4e2a\u53d8\u91cf\u7684\u503c\u653e\u5230\u5bc4\u5b58\u5668\u91cc\u9762\uff0c<br \/>\u7136\u540e\u5bc4\u5b58\u5668\u7684\u503c\u4e0d\u4f1a\u518d\u88ab\u66f4\u65b0\uff0c\u6240\u4ee5\u5c31\u9020\u6210\u4e86\u6b7b\u5faa\u73af<\/p>\n<p>\u5177\u4f53\u53c2\u8003\u8fd9\u4e2a https:\/\/github.com\/jonwinters\/jmm-research \u7684\u7b2c\u4e00\u8282\u90e8\u5206\uff0c\u6709\u8be6\u7ec6\u7684\u6c47\u7f16\u4ee3\u7801\u89e3\u91ca                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653084\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lewis89 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ignor <br \/>@wwqgtxx <br \/>@az467 <\/p>\n<p>\u53cd\u6c47\u7f16\u770b\u4e00\u4e0b\u5c31\u77e5\u9053\u662f\u865a\u62df\u673a JIT \u7684\u95ee\u9898\uff0c<br \/>\u8fd9\u79cd\u95ee\u9898\u672c\u6765\u5c31\u662f\u532a\u5937\u6240\u601d\u7684\uff0c\u5bf9\u4e8e static \u975e volatile \u53d8\u91cf\uff0cJVM \u7f16\u8bd1\u6210\u672c\u5730\u4ee3\u7801\u7684\u65f6\u5019\u5077\u61d2\u4e86\uff0c<br \/>JVM \u8ba4\u4e3a static \u975e volatile \u53d8\u91cf\u4e0d\u503c\u5f97 \u53cd\u590d\u901a\u8fc7\u5185\u5b58\u5bfb\u5740\u5230\u5806\u5185\u5b58\u53bb\u8bfb\u53d6\u5b83\u7684\u503c\uff0c<br \/>\u6240\u4ee5\u53ea\u8bfb\u53d6\u4e86\u4e00\u6b21 \u653e\u5230 CPU \u7684\u5bc4\u5b58\u5668\u91cc\u9762\u5c31\u5b8c\u4e8b\u4e86\uff0c\u8fd9\u6837 CPU \u6c38\u8fdc\u89c2\u6d4b\u4e0d\u5230\u6700\u65b0\u7684\u503c\uff0c<br \/>\u5728\u67d0\u4e9b\u4f4e\u7248\u672c\u7684 JDK8 \u6216\u8005 ARM \u5e73\u53f0 \u8fd9\u4e2a\u4ee3\u7801\u662f\u53ef\u4ee5\u9000\u51fa\u7684<\/p>\n<p>\u5177\u4f53\u53c2\u8003\u6211\u5199\u7684\u8fd9\u7bc7\u6587\u7ae0 jmm-research<br \/>\u91cc\u9762\u6709\u8be6\u7ec6\u7684\u53cd\u6c47\u7f16\u4ee3\u7801                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653085\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lewis89 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lewis89 https:\/\/github.com\/jonwinters\/jmm-research\/blob\/master\/pic\/radical-compile.png                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653086\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : OliverDD <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u662f\u5185\u5b58\u4e00\u81f4\u6027\u95ee\u9898\uff0c\u89e3\u51b3\u529e\u6cd5\u597d\u51e0\u4e2a\uff0c\u539f\u5b50\u53d8\u91cf\u3001volatile \u3001\u751a\u81f3\u540c\u6b65\u7b56\u7565\u4e5f\u53ef                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653087\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bugmakerxs <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u76f4\u63a5\u770b.class \u547d\u4ee4\u770b\u770b\uff0c\u6211\u8bb0\u5f97\u80fd\u770b\u5230\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653088\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : BBCCBB <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b jvm \u5185\u5b58\u6a21\u578b\u548c volatile \u505a\u4ec0\u4e48\u7684\u5c31\u77e5\u9053\u4e86.<\/p>\n<p>\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u6709\u81ea\u5df1\u7684\u5de5\u4f5c\u5185\u5b58.. \u4e0d\u52a0 volatile, \u53d8\u91cf\u88ab\u7f13\u5b58\u5728\u7ebf\u7a0b\u7684\u5de5\u4f5c\u5185\u5b58\u4e2d, <\/p>\n<p>\u5176\u4ed6\u7ebf\u7a0b\u5199\u5165\u540e\u4e5f\u611f\u77e5\u4e0d\u5230.                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653089\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : WngShhng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             ![QQ \u622a\u56fe 20210404114503.png]( https:\/\/p9-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/adbe6a490e3e4481a6efea21dbf0a5e2~tplv-k3u1fbpfcp-watermark.image)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653090\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : WngShhng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @WngShhng <br \/>Reports on while loops which spin on the value of a non-volatile field, waiting for it to be changed by another thread.<br \/>In addition to being potentially extremely CPU intensive when little work is done inside the loop, such loops are likely have different semantics than intended, as the Java Memory Model allows such field accesses to be hoisted out of the loop, causing the loop to never complete even if another thread does change the field&#8217;s value.<br \/>Additionally since Java 9 it&#8217;s recommended to call Thread.onSpinWait() inside spin loop on a volatile field which may significantly improve performance on some hardware.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653091\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Martens <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             ready \u52a0\u4e0a volatile \u4fee\u9970\u5c31\u884c\u4e86, \u4fdd\u8bc1 ready \u53d8\u91cf\u7684\u7ebf\u7a0b\u53ef\u89c1\u6027&#8230;&#8230;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653092\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : johnniang <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53cd\u7f16\u8bd1\u4e00\u4e0b\u5c31\u77e5\u9053\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653093\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : FrankHB <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u600e\u4e48\u968f\u4fbf\u8fdb\u4e00\u4e2a\u90fd\u662f\u5404\u79cd\u4e0d\u5230\u70b9\u4e0a\u7684\u2026\u2026<br \/>\u6839\u672c\u539f\u56e0\u662f Java \u8bed\u8a00\u4e0d\u4fdd\u8bc1\u8fd9\u91cc\u7684\u8c03\u5ea6\u516c\u5e73\u6027\uff0c\u6240\u4ee5\u660e\u786e\u5141\u8bb8\u628a\u4f60 = true \u997f\u6b7b\u4e86\u4e0d\u7ba1\u3002<br \/>\u8fd9\u73a9\u610f\u513f\u8ddf\u53ef\u89c1\u6027\u770b\u8d77\u6765\u8868\u9762\u4e0a\u662f\u6709\u70b9\u5173\u7cfb\uff0c\u4f46\u4e0d\u5de7\uff0cJava \u91cc\u8fd9\u6761\u6070\u6070\u662f\u5355\u72ec\u62ce\u51fa\u6765\u6388\u6743\u7684\uff1a<\/p>\n<p>https:\/\/docs.oracle.com\/javase\/specs\/jls\/se16\/html\/jls-17.html#jls-17.4.9<\/p>\n<p>Programs can hang if all threads are blocked or if the program can perform an unbounded number of actions without performing any external actions.<\/p>\n<p>\u8fd9\u6837\u8bbe\u8ba1\u7684\u7406\u7531\uff0c\u5728 JSR-133 Chapter 13 \u91cc\u6709\u63d0\uff0c\u662f\u4e2a\u59a5\u534f\uff1a<\/p>\n<p>https:\/\/www.cs.umd.edu\/~pugh\/java\/memoryModel\/jsr133.pdf<\/p>\n<p>\uff08\u8001\u5b9e\u8bf4\u8fd9\u6837\u8bbe\u8ba1\u633a\u6b20\u6241\u7684\uff0c\u867d\u7136\u8fd8\u6709\u4eba\u5c45\u7136\u8ba4\u4e3a\u8fd9\u4e2a\u201c\u5bb9\u6613\u7406\u89e3\u201d\uff1a https:\/\/stefansf.de\/post\/non-termination-considered-harmful\/ \u2190\u6ce8\u610f\u8fd9\u4eba\u8bf4\u7684 C \u548c C++ \u5728\u8fd9\u91cc undefined behavior \u8fd9\u4e2a\u660e\u786e\u662f\u9519\u7684\u3002\uff09<\/p>\n<p>@az467 \u4f60\u786e\u5b9a\u8fd9\u95ee\u9898\u771f\u7ecf\uff1f<\/p>\n<p>\u548c\u4f60\u8bf4\u7684\u6070\u6070\u76f8\u53cd\uff0c\u9664\u4e86 JVM \u81ea\u5df1\u9ad8\u5174\u662f\u4e0d\u662f\u613f\u610f\u8fd9\u6837\u641e\uff0c\u8fd9\u8ddf JVM \u6ca1\u6709\u534a\u70b9\u5173\u7cfb\u3002<br \/>\u5173\u6389 JIT \u4e5f\u4e0d\u4fdd\u8bc1\u4e00\u5b9a\u9876\u7528\u3002<\/p>\n<p>@ipwx C++ \u548c\u8fd9\u4e2a\u660e\u663e\u4e0d\u4e00\u6837\u3002<\/p>\n<p>C++ \u662f\u660e\u786e\u5141\u8bb8 forward prograss\uff0c\u53cd\u9762\u5141\u8bb8\u628a\u6574\u4e2a while \u76f4\u63a5\u4f18\u5316\u6ca1\u6389\u800c\u4e0d\u662f blocking\uff1a<\/p>\n<p>C++17 \u00a7 4.7.2 Forward progress \u00b6 1<\/p>\n<p>The implementation may assume that any thread will eventually do one of the following:<\/p>\n<p>&#8211; terminate,<br \/>&#8211; make a call to a library I\/O function,<br \/>&#8211; perform an access through a volatile glvalue, or<br \/>&#8211; perform a synchronization operation or an atomic operation.<\/p>\n<p>[Note: This is intended to allow compiler transformations such as removal of empty loops, even when termination cannot be proven. \u2014 end note]<\/p>\n<p>\u867d\u7136\u53ea\u662f\u5141\u8bb8\uff0c\u6240\u4ee5\u5b9e\u73b0\u4e0a\u53ef\u80fd\u521a\u597d\u4e00\u6837\u2026\u2026<\/p>\n<p>\u53e6\u5916\u6ce8\u610f C++ \u8fd9\u91cc\u662f\u6bcf\u7ebf\u7a0b\u5185\u7684\u7ea6\u675f\u3002Java \u7684 volatile \u81ea JDK 1.4 \u540e\u8ddf C++11 \u7684 std::atomic \u8bed\u4e49\u7c7b\u4f3c\uff0c\u4f46\u8fd9\u91cc C++ \u53ef\u662f volatile \u5c31\u591f\u4e86\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653094\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : FrankHB <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \uff08\u5f53\u7136 C++ \u7684 volatile \u5c31\u591f\u4e86\u53ea\u662f\u8bf4\u770b\u8d77\u6765\u7684\u6b7b\u5faa\u73af\u4e0d\u88ab\u4f18\u5316\u6ca1\u6389\uff0c\u591a\u7ebf\u7a0b\u8fd8\u662f\u8be5 atomic \u5c31 atomic \u8be5\u52a0\u9501\u5c31\u52a0\u9501\uff0c\u5426\u5219 data race \u4e86\u6b7b\u5f97\u66f4\u96be\u770b\u3002\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653095\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ipwx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @FrankHB \u561b\u561b\uff0c\u6211\u63d0\u4e00\u5634 C++\uff0c\u4e3b\u8981\u662f\u5410\u4e2a\u5608\u3002\u6211\u51e0\u4e4e\u4e0d\u61c2 Java \u3002<br \/>&#8212;-<\/p>\n<p>C++ \u7684 atomic \u8981\u4fdd\u8bc1\u7684\u6bd4 empty removal \u8981\u591a\u4e86\u53bb\u4e86\u3002\u8b6c\u5982\u7f16\u8bd1\u5668\u6216\u8005 cpu \u53ef\u4ee5 out-of-order execution\uff0c\u53ef\u4ee5\u5728\u8bfb\u53d6\u4e86\u67d0\u4e2a\u53d8\u91cf\u4ee5\u540e\u5047\u8bbe\u5b83\u4e0d\u53d8\u6240\u4ee5\u4e0d\u8bfb\u7b2c\u4e8c\u904d etc \u3002\u3002\u3002\u3002 \u540e\u9762\u90a3\u79cd\u60c5\u51b5\u7528 volatile \u8fd8\u884c\uff0cOut-of-order execution \u7528 volatile \u5c31\u4f1a\u6b7b\u7684\u5f88\u96be\u770b\u3002\u3002\u3002\u8fd9\u4e5f\u662f\u4e3a\u5565\u6211\u5728\u5199\u591a\u7ebf\u7a0b\u7a0b\u5e8f\u4ece\u6765\u4e0d\u7528 volatile \uff08\u53cd\u6b63\u6ca1\u5375\u7528\uff09                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653096\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ipwx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8230; \u7528 atomic \u7684 memory fence \u5c31\u80fd\u5f88\u597d\u89e3\u51b3 out-of-execution \u95ee\u9898\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653097\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : az467 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @FrankHB <\/p>\n<p>\u554a\uff1f<\/p>\n<p>Chapter 13 \u7684\u4f8b\u5b50\u4e2d\u7a0b\u5e8f\u6709\u52a0\u9501\uff0c\u5e76\u4e14\u6ca1\u6709 external action\uff0c\u6240\u4ee5\u7528 fairness \u89e3\u91ca\u4e3a\u4ec0\u4e48\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u88ab\u4f18\u5316\u6210\u6b7b\u5faa\u73af\u3002<\/p>\n<p>\u539f po \u7684\u4ee3\u7801\u91cc\u751a\u81f3\u90fd\u6ca1\u6709\u51fa\u73b0\u8fc7 synchronized\/volatile\uff0c\u4efb\u4f55 happens before \u5173\u7cfb\u90fd\u6ca1\u6709\uff0c<br \/>\u5c31\u7b97 Java \u4fdd\u8bc1\u8c03\u5ea6\u516c\u5e73\uff0c\u96be\u9053 JIT \u7f16\u8bd1\u5668\u5c31\u4e0d\u4f18\u5316\u4e86\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653098\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : FrankHB <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @az467 \u539f\u95ee\u9898\u662f\u201c\u8bf4\u7684\u4e0d\u6e05\u695a\u2026\u2026\u5177\u4f53\u662f\u4ec0\u4e48\u539f\u56e0\u5462\uff1f\u201d\u5149\u770b\u8fd9\u91cc\uff0c\u4f60\u56de\u7b54\u4e00\u4e2a\u5177\u4f53\u5b9e\u73b0\u7684\u8868\u73b0\u5012\u4e5f\u7b97\u662f\u5bf9\u8def\u3002<br \/>\u4f46\u540e\u9762\u7684\u7591\u95ee\u5f88\u660e\u663e\u662f\u4e3a\u4ec0\u4e48\u5141\u8bb8\u8fd9\u6837\u505a\u3002\u62ff\u5b9e\u73b0\u884c\u4e3a\u5c31\u6ca1\u89e3\u51b3\u95ee\u9898\u3002<br \/>\u5173\u952e\u662f\u4ec0\u4e48\u5141\u8bb8\uff0c\u76f4\u63a5\u7684\u7b54\u6848\u5c31\u662f JLS \u91cc\u7684\u89c4\u5219\u3002\uff08\u4e8b\u5b9e\u4e0a\u8fd9\u6bb5 JSR133 \u91cc\u4e5f\u6709\u3002\uff09<br \/>\u867d\u7136\u8ddf\u4f60\u4e4b\u540e\u8bf4\u7684\u4e00\u6837\uff0c\u6700\u597d\u770b\u770b\u6574\u4e2a JMM\uff0c\u4f46\u76f4\u63a5\u539f\u56e0\u662f JLS \u5c31\u786e\u5b9a\u7684\uff0c\u5230\u8fd9\u91cc\u8ddf JVM \u8fd8\u4e0d\u9700\u8981\u6709\u5173\u7cfb\u3002<br \/>\uff08\u53ef\u80fd\u8fd9\u91cc\u662f\u8be5\u5f3a\u8c03\u4e00\u4e0b\u6240\u8c13\u7f16\u8bd1\u5668\u5305\u62ec JVM \u7684 JIT \u800c\u4e0d\u53ea\u662f javac \u3002\u4e0d\u8fc7\u6ca1\u770b\u51fa\u4e00\u5f00\u59cb\u8fd9\u91cc\u662f\u4e0d\u662f\u6709\u7591\u95ee\u3002\uff09<br \/>\u62ff JSR133 \u4e3b\u8981\u662f\u8bf4\u660e\u80cc\u666f\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u7528\u5230\u7684\u662f Chapter 13 \u91cc\u7684\u7b2c\u4e00\u6bb5\u6587\u5b57\u63cf\u8ff0\u3002<br \/>Figure 27 \u662f\u4e00\u4e2a\u5178\u578b\u7684\u4f8b\u5b50\uff0c\u6709\u4e86 synchronize \u90fd\u5141\u8bb8\u4e0d\u8ba9\u51fa CPU\uff0c\u6bd4\u8fd9\u91cc\u7684\u6761\u4ef6\u8fd8\u5f3a\u3002\uff08\u53e6\u5916\u522b\u5fd8\u4e86 happens before \u5728\u7ebf\u7a0b\u5185\u5c31\u6709\u6548\uff0c\u4e0d\u8fc7\u8fd9\u4e2a\u548c\u8fd9\u91cc\u7684\u95ee\u9898\u6ca1\u76f4\u63a5\u5173\u7cfb\u3002\uff09<br \/>\uff08\u540e\u9762\u90a3\u4e2a Figure 28 \u4f8b\u5b50\u662f\u53cd\u8fc7\u6765\u9650\u5236\u4f18\u5316\u7684\uff0c\u548c\u8fd9\u91cc\u4e5f\u4e0d\u76f4\u63a5\u76f8\u5173\u3002\uff09<br \/>\u91cd\u65b0\u56de\u987e\u91cd\u70b9\uff1a\u4e0d\u662f\u201c\u4f18\u5316\u201d\uff08\u800c\u662f\u4e3a\u4ec0\u4e48\u5141\u8bb8\u4f18\u5316\uff09\u3002\u5b9e\u9645\u4e0a\u8003\u8651\u8fd9\u91cc\u4ecd\u7136\u4e0d\u9700\u8981\u5173\u5fc3\u201c\u7f16\u8bd1\u5668\u600e\u4e48\u4f18\u5316\u201d\u3002\u8bf4\u767d\u4e86\uff0c\u7f16\u8bd1\u5668\u5c31\u7b97\u4e0d\u662f\u4ee5\u4f18\u5316\u7684\u76ee\u7684\u53d8\u6362\u4ee3\u7801\uff0c\u76f4\u63a5\u7f16\u8bd1\u6210\u8fd9\u6837\u6309\u89c4\u8303\u4e5f\u6ca1\u8bdd\u8bf4\u3002<br \/>\u6ca1\u8bb2\u6e05\u695a\u8fd9\u6761\u7ebf\uff0c\u8bb2\u5b9e\u73b0\u7ec6\u8282\u53ea\u4f1a\u66f4\u6df7\u4e71\u3002<br \/>\u7528 volatile \u7b49\u907f\u514d\u95ee\u9898\u4e5f\u662f\u4e4b\u540e\u7684\u5ef6\u4f38\u8bdd\u9898\u3002<br \/>\uff08\u9053\u7406\u4e0a happens before \u4e5f\u8be5\u5f04\u660e\u767d\uff0c\u4f46\u5c34\u5c2c\u7684\u662f\u8fd9\u4e2a\u53ea\u7528\u7ebf\u7a0b\u5185\u7684\u5c31\u80fd\u76f4\u63a5\u8e29\u4e0a\u8c03\u5ea6\u95ee\u9898\u4e86\uff0c\u53c8\u4e0d\u50cf C\/C++ \u76f4\u63a5\u6709 sequence before\uff0c\u8fd8\u4e0d\u5982\u9ed8\u8ba4\u77e5\u9053 program order \u4e0d\u8a00\u81ea\u660e\u4e86\u2026\u2026\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653099\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mdkml <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @az467 #13 <\/p>\n<p> \u5982\u679c\u628a run \u65b9\u6cd5\u66ff\u6362\u6210\u4e0b\u9762\u8fd9\u79cd<\/p>\n<p> public void run() {<\/p>\n<p> while (!ready) {<br \/> System.out.println(ready);<br \/> System.out.println(number);<br \/> System.out.println();<br \/> }<br \/> System.out.println(ready);<br \/> System.out.println(number);<br \/> System.out.println();<br \/> }<\/p>\n<p>\u5c31\u53c8\u53ef\u4ee5\u505c\u4e0b\u4e86\uff0c\u4f60\u8bf4\u7684\u2018\u751a\u81f3\u53ef\u4ee5\u53cd\u8fc7\u6765\u201c\u4fdd\u8bc1\u201d\u53d8\u91cf\u5b8c\u5168\u4e0d\u53ef\u89c1\u3002\u2019\u597d\u50cf\u4e0d\u592a\u5bf9\u5440\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5653100\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : az467 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @mdkml <br \/>1. \u53ef\u4ee5 \u4e0d\u662f \u5fc5\u987b\u3002<br \/>2. println() \u5185\u90e8\u9501\u4f4f\u4e86 System.out \uff0c\u800c\u4e14\u662f\u5728\u5faa\u73af\u4f53\u5185\u90e8\u8c03\u7528\uff0c\u8fd9\u7ed9 Hotspot \u7684\u4f18\u5316\u65b9\u5f0f\u9020\u6210\u4e86\u5f71\u54cd\uff0c\u6240\u4ee5\u5728\u8fd9\u91cc\u7a0b\u5e8f\u53ef\u4ee5\u7ec8\u6b62\u3002 <br \/>\u4f46\u662f\u6362\u6210\u53e6\u5916\u4e00\u79cd jvm \/ \u5e73\u53f0\u5c31\u53c8\u4e0d\u4e00\u5b9a\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u521a\u5b66\u591a\u7ebf\u7a0b\uff0c\u8bf7\u95ee\u4e0b\u9762\u8fd9\u6bb5\u7a0b\u5e8f\u4e3a\u4ec0\u4e48&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/428303"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=428303"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/428303\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=428303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=428303"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=428303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}