???????Java????????volatile
???????????? ???????[ 2013/3/19 10:15:08 ] ????????
???????????A???writer()??????????B???reader()??????????happens before????????????????happens before ?????????????
????1???????????????1 happens before 2; 3 happens before 4??
????2??????volatile????2 happens before 3??
????3??????happens before ??????????1 happens before 4??
????????happens before ???????λ???????????£?
??????????У?????????????????????????????happens before ?????????????????????????????????volatile??????????????????Щ?????????happens before?????
????????A???д???volatile??????B????????volatile??????A?????дvolatile?????????п??????????????B????????volatile????????????????B???????
????volatileд-???????????
????volatileд????????????£?
?????? ??д???volatile???????JMM??????????????????е?????????μ?????檔
?????????????????VolatileExample????????????A???????writer()????????????B???reader()?????????????????????????е?flag??a??????????????????A???volatileд???????????????????
?????????????????A??дf(shuō)lag?????????????A?б????A???1?????????????????????μ???????С?????????????A????????е??????????????μ??
????volatile??????????????£?
?????? ???????volatile???????JMM??????????????????????Ч????????????????????ж???????????
?????????????B??????volatile???????????????????????
?????????????????flag?????????????B??????????Ч??????????B???????????ж??????????????B?????????????±??????B????????е????????????????μ????
????????????volatileд??volatile????????????????????????????????B?????volatile??????д???A??д???volatile?????????п?????????????????????????????B?????
?????????volatileд??volatile??????????????????
?????? ???Aд???volatile????????????????A???????????????volatile?????????????????????????????????????????
?????? ???B?????volatile????????????????B??????????????????????д???volatile????????????????????????????
?????? ???Aд???volatile????????????B?????volatile???????????????????????A?????????????B?????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11