???????????? Java???????е?????????????????? ?????:
????????????????????????????????е?????????Υ?????????????????????????????ж???????????????????????????д????????????????????????????顣???????????????????д???????????????????????????
??????????????????????????????????????????????????????????????????????????????????????????????:??volatile???ε???????????п?????volatile???ε?????????????????????????????????????檔??????????????????????????????????????volatile??????????????????п?????????????????????????????volatile int a=0;????????????a++;???????a???п?????????a++????????????????????????????????????????????
??????java??volatile??synchronized??final???????
?????????:
????????????????С??λ?????в????????????a=0;(a??long??double????)
??????>????????????????????????????????(sychronized)?????????????????????????????????????????????????????????Java??concurrent?????????Щ??????????????????API???????Щ???????÷???????:AtomicInteger??AtomicLong??AtomicReference??
??????Java??synchronized????lock??unlock?в???????????
??????????:
????Java????????volatile??synchronized????????????????????????????????volatile????????????”????????????”?????壬synchronized????”???????????????????????????????lock????????????????????????????????????????????????????????С?
?????????????????Java Concurrency in Practice????
??????????δ?????????????£???????????
????public class NoVisibility {
????private static boolean ready;
????private static int number;
????private static class ReadyThread extends Thread{
????@Override
????public void run() {
????while(!ready) {
????Thread.yield();
????}
????System.out.println(number);
????}
????}
????public static void main(String[] args) {
????new ReadyThread().start();
????number=42;
????ready=true;
????}
????}