ࡱ> Root Entrya&FileHeaderLDocInfoDBodyText [ \ !"#$%&')*(+,-./015Root Entryށ &FileHeaderLDocInfoDBodyText ށށ 234 !"#$%&'()*+,-./0123456789:;=>?@ABCEFGHIJKPMNOQRSUVYZ[\]^_`bcdefghijklmnopqrstuvwxyz{|}~HwpSummaryInformation.<PrvImage PrvTextDocOptions ށށSection0apScripts ށށJScriptVersion W DefaultJScriptT_LinkDocX Chap.14 Android: Synchronization ٳ0T (Synchronization) 5. , (p.481) 0 'ٳ0T' 8 ½D h|\. ..... LunarView.java ~~~ synchronized (mSurfaceHolder){ doDraw(c); } " Concurrency control - http://en.wikipedia.org/wiki/Synchronization_(computer_science) e.g., P X hwp \t 'ٳ' X՘X fileD update? - mutual exclusion ! semaphore/lock http://en.wikipedia.org/wiki/Mutual_exclusion http://en.wikipedia.org/wiki/Semaphore_(programming) - 'deadlock' problem " Java - 'synchronized' keyword `$  method| blockXՔ ) a$  resource(e.g., )| blockXՔ ) <// SyncDemo1.java // #1)  method| blockXՔ )... public class SyncDemo1 implements Runnable { private StringBuffer buf=new StringBuffer(); @Override public void run(){ printName(); } // public void printName(){ // no 'synchronized'... public synchronized void printName(){ for(int i=0;i<10;i++){ buf.append(Thread.currentThread().getName()); System.out.println(>{GIF89aɻxxxkkk]]]PPPCCC555((( d`LH00`Hذ̘`H0|pdXL@`0H `H0`dHL`H0xp`XH@0d LȰ``HH00dLؘȀ`H0xp`XH@d0L `H0d`LH`H0|pdXL@0`$H`dHL00`HذȘdL0xp`XH@0` HdH0ȳ``HHdL0xp`XH@`0H Ը̰ĠऀؘpȈXxHp@h@d8`8X0xT0pH dxddxd`d`p`|``x`p``x`!, H*\ȰÇ#JHŋ3jȱǏ CIɓ(S\ɲ˗0cʜI͛8sɳϟ@ JѣH*]ʴӧPJJիXjʵׯ`ÊKٳUp-lƕK޷x{a+K0sCVxe~7ϠCMӨS^wq̓Žۙ/fl[!׻'X{8-_μУK>u֯gߞ}uܩ#?ɟ޼䷯o~>'DO;4V`7 p avJ& nAXg^h [ q| (,FWXA2f0 0BTc@ieBiHu -I%e3VڒXfXZx#Wr)&^~mN&3G&ppixvo*蠄j*Ǒi}FJjk2Aj)|AjjyNUZ+6*+k,6塉uf)UK#leb!XJYyԶ}{: &vQRTobڟFhk`"e 7<*xZW;dqL#{)REl3F72ʾ` ,f`-dm6FJx'p3ZҤ]p#JWꊸDxmU%.;V'j"w}8J[q~P]^fKRUf&^u'CKk{D.o'7G/Wogw/o觯ʻ,K@;a``a`0x`a``a`0x  l x sec2013D 10 1| T֔| $ 5:33:01sec-7, 5, 10, 583 WIN32LEWindows_Unknown_Version@Pր@ށ@ҁH"Ua`CĜ!*Ab@P1헿o@ǿ>8qTTHdHj  s! Ua`CĜ!*Ab@P1&,HHT l8`l?w|y 5Esfɳ:b줣 z.OSG)T^"1#-+x Ϋ>7>&ѭϼ*5[g$ʨ.쇌hWETx/꣪@|=633teWJ>-5 ;s;L鉯nZ: *患5HAMy)^ui6\lƃ!f=,\l΃W2lb=X)"mo?%aI-j o՛|`2QG_a2I!v#̽$o% ^v$˝0. 7Z[ī5Χ Ld\c  ߈u@DO 6C,H,#GB!k0~ 6*7=M*Z:ҙ#?*?ӿT@Y~X+mj3'm[v|:j)%C$Mϼ5#().getName() + i + " 4 .cd߈ } System.ou2s .Ҩm|=-T$gNCEJpNڈgqSp^z@ .NPodYq]%q2*Vq +þ82#-o`"_*C_mhT4X>܊O{e{l*:a?YB[:S:S.TķsR&3+Q;SAf(cځ-ߚ#՜R2P+__F8UtnUN՟~HHWP Document Fileffer(); @Override public void run(){ printName(); } // public void printName(){ // no 'synchronized'... public synchronized void printName(){ for(int i=0;i<10;i++){ buf.append(Thread.currentThread().getName()); System.out.printlЈRM|] ׌a}J5qt =mZU^wCҨB}{HҾ&V_hU?ߗ581ŹaeEu9CI֦IhSgݔ00Ň)>(IP瘂jE L̃>qs|ɗ컻 .7=9ssR:BD$,I4*dȦT2@Hez”ϝɹ0F!)ӔctPR4Oy!HNdI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`~i0mzEA!jSqߊ&я>>r[}L}";3Cv\';M(L)}Nf#S[D !"#$%&'()*+,-./0123456789:;=>?@ABCEFGHIJKPMNOQRSUVYZ[\]^_`bcdefghijklmnopqrstuvwxyz{|}~HwpSummaryInformation.<PrvImage PrvTextDocOptions aaSection0apScripts aaJScriptVersion W DefaultJScriptT_LinkDocX Chap.14 Android: Synchronization ٳ0T (Synchronization) 5. , (p.481) 0 'ٳ0T' 8 ½D h|\. ..... LunarView.java ~~~ synchronized (mSurfaceHolder){ doDraw(c); } " Concurrency control - http://en.wikipedia.org/wiki/Synchronization_(computer_science) e.g., P X hwp \t 'ٳ' X՘X fileD update? - mutual exclusion ! semaphore/lock http://en.wikipedia.org/wiki/Mutual_exclusion http://en.wikipedia.org/wiki/Semaphore_(programming) - 'deadlock' problem " Java - 'synchronized' keyword `$  method| blockXՔ ) a$  resource(e.g., )| blockXՔ ) <// SyncDemo1.java // #1)  method| blockXՔ )... public class SyncDemo1 implements Runnable { private StringBuffer buf=new StringBuffer(); @Override public void run(){ printName(); } // public void printName(){ // no 'synchronized'... public synchronized void printName(){ for(int i=0;i<10;i++){ buf.append(Thread.currentThread().getName()); System.out.println(>{GIF89aɻxxxkkk]]]PPPCCC555((( d`LH00`Hذ̘`H0|pdXL@`0H `H0`dHL`H0xp`XH@0d LȰ``HH00dLؘȀ`H0xp`XH@d0L `H0d`LH`H0|pdXL@0`$H`dHL00`HذȘdL0xp`XH@0` HdH0ȳ``HHdL0xp`XH@`0H Ը̰ĠऀؘpȈXxHp@h@d8`8X0xT0pH dxddxd`d`p`|``x`p``x`!, H*\ȰÇ#JHŋ3jȱǏ CIɓ(S\ɲ˗0cʜI͛8sɳϟ@ JѣH*]ʴӧPJJիXjʵׯ`ÊKٳUp-lƕK޷x{a+K0sCVxe~7ϠCMӨS^wq̓Žۙ/fl[!׻'X{8-_μУK>u֯gߞ}uܩ#?ɟ޼䷯o~>'DO;4V`7 p avJ& nAXg^h [ q| (,FWXA2f0 0BTc@ieBiHu -I%e3VڒXfXZx#Wr)&^~mN&3G&ppixvo*蠄j*Ǒi}FJjk2Aj)|AjjyNUZ+6*+k,6塉uf)UK#leb!XJYyԶ}{: &vQRTobڟFhk`"e 7<*xZW;dqL#{)REl3F72ʾ` ,f`-dm6FJx'p3ZҤ]p#JWꊸDxmU%.;V'j"w}8J[q~P]^fKRUf&^u'CKk{D.o'7G/Wogw/o觯ʻ,K@;a``a`0x`a``a`0x  l x sec2013D 10 1| T֔| $ 5:33:01sec-7, 5, 10, 583 WIN32LEWindows_Unknown_Version@Pր@ \@ҁH"Ua`CĜ!*Ab@P1헿o@ǿ>8qTTHdHj  s! Ua`CĜ!*Ab@P1&,HHT l8`l?w|y 5Esfɳ:b줣 z.OSG)T^"1#-+x Ϋ>7>&ѭϼ*5[g$ʨ.쇌hWETx/꣪@|=633teWJ>-5 ;s;L鉯nZ: *患5HAMy)^ui6\lƃ!f=,\l΃W2lb=X)"mo?%aI-j o՛|`2QG_a2I!v#̽$o% ^v$˝0. 7Z[ī5Χ Ld\c  @DO 6C,H,#GB!k0~ 6*7=M*Z:ҙu@DO 6C,H,#GB!k0~ 6*7=M*Z:ҙ#?*?ӿT@Y~X+mj3'm[v|:j)%C$Mϼ5#cd߈(); } // publ2s .Ҩm|=-T$gNCEJpNڈgqSp^z@ .NPodYq]%q2*Vq +þ82#-o`"_*C_mhT4X>܊O{e{l*:a?YB[:S:S.TķsR&3+Q;SAf(cځ-ߚ#՜R2P+__F8UtnUN՟~HHWP Document Fileffer(); @Override public void run(){ printName(); } // public void printName(){ // no 'synchronized'... public synchronized void printName(){ for(int i=0;i<10;i++){ buf.append(Thread.currentThread().getName()); System.out.printlֈ F d$m&Elk%H&L'i&3C&2.? EYV_hU?ߗ581ŹaeEu9CI֦IhSgݔ00Ň)>(IP瘂jE L̃>qs|ɗ컻 .7=9ssR:BD$,I4*dȦT2@Hez”ϝɹ0F!)ӔctPR4Oy!HNdIci"yDIiڅڮAg-.ك8;c"ns?^5>OJ?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