Table Of Content�
CraiMgu ndie,
Forewobryd ChieRfe searacnhdS tratOefgfyi cMeirc,r osoft
T T
Concrurent
Progranmgm i
onW indows
.nrR
Development
Series
Duffy
Joe
PraifsoeCr o ncurrPernotg rammionnWg i ndows
"Ih ave befeans cinawtietdhc oncurreenvceysr i ncIea ddedt hreadisnugp port
tot heC ommonL anguagReu ntimae d ecadaeg oT.h at'asl swoh ereIm etJ oe,
who isa worlde xperotn thitso piTch.e sdea ysc,o ncurreinscay f irst-order
concefronpr r acticaalldlle yv elopeTrhsa.n kg oodnefsosJr oe'bso okI.ti sa t our
def orcaen dI s halrle loyn i tf orm anyy eartso c ome."
-ChrBirs ummDei,s tingEunigsihneMedie crr,o soft
"Ifi rsmte tJ oew henw e wereb othw orkinwgi tht heM icrosoCfLtR t eamA.t t hat
timew,e hads everdails cussiaobnosu tt hreadianngd i tw asa pparetnhta t
he wasa sp assionaabtoeu tt hissu bjeacstI was.L aterJ,o et ransititoon ed
MicrosofPta'rsa llCeolm putinPgl atfotrema mw herea loto fh isg oodi deas
aboutth readicnogu lcdo met of ruitiMoons.tt hreadianngdc oncurrebnocoyk s
thaIth avec omea croscso ntaiinnf ormattihoanit s i ncorraencdte xplaihnosw
tos olvceo ntrivperdo blemtsh agto oda rchitecwtouurledn evegre ty oui ntion
thef irpslta cJeo.e 'bso oki so neo ft hev eryf ewb ookst haItr espeocnt t he
mattearn,d t hirse speccotm esf romk nowinJgo e'ksn owledgeex,p erienacned,
hisa bilittoey x placionn cepts."
-JeffrReiyc hWtienrt,e llect
"Theraer ef ewa reaisnc omputitnhga atr ea si mportaonrts ,h roudeidnm yste,r y
asc oncurre.In tc'ynso ts implaen,d D uffdyo esnc'lta itmo m akei ts o-buat rmed
witht her ighitn formatainodne xcellaednvti ccer,e aticnogr reacntd h ighly
scalabslyes temissa tl easpto ssibElvee.r sye lf-respeWcitnidnogw sd eveloper
shoulrde adt hibso ok."
-JonatShkaenSe otf,t wEanrgei nCeleera,r swift
"WhatIl ovaeb outth ibso oki st haitti sb othc omprehensiinvi et cso veraogfe
concurreonnct yh eW indowsp latforamsw, e lals v eryp ractiicnai ltp sr esen
tatioonf t echniquiemsm ediatealpyp licatbolr ee al-worslodf twadreev el
opmentJ.o e'bso oki sa 'mushta ver'e sourfcoera nyonbeu ildinnagt ivoer
managecdo deW indowsa pplicattihoanltse veracgoen currency!"
-SteTveei xeira,U niPMtra ondaugcetr ,
ParaClolmeplu tPilnagt fMoircmr,o Csoorfpto ration
"Thibso oki sa fabulocuosm pendiuomf b otht heoretikcnaolw ledgaen d
practigcuaild anocnew ritienffge cticvoen curraepnptl icatJiooenD su.f fiys n ot
onlya preeminent eixnpt ehreat r to fd eveloping parallel faoprp lications
Windowsh,e 'asl sao t ruset udenotft hea rto fw ritinFgo.rt hibso okh,e h as
combinetdh ostew os kislelt tso c reawthea td eservaensd i sd estinteodb ea
long-stancdliansgs iindc e velopehrasn'd se verywheIIr e.
-StephTeonuP br,o grMaamn agLeera Pda,r aClolmeplu tPilnagt fMoircmr,o soft
IIA sc hidpe signerrusno uto fw ayst om aket hei ndividcuhailfp a sttehre,hy a ve
movedt owardasd dinpga ralcloemlp utcea paciitnys teaCdo.n sumePrC sw ith
multipcloer easr en ow commonplacWee. a rea ta n inflectpiooinn wth ere
improvepde rformanwcieln lo l ongecro mef romf astcehri pbsu tr athefrr om
oura biliatssy o ftwadreev elopetroes x plociotn curre.nU cnyderstandtihneg
concepotfsc oncurrent prograanmdmh ionwg t ow ritceo ncurrecnotd eh as
therefboerceo mae c rucipaalr otf w ritisnugc cessful soWfittwhCa orne.c urrent
ProgramomniW nign doJwoseD, u ffhya sd onea greajto be xplaining concurrent
concepftrso mt hef undamenttahlrso ugahd vancetde chniquTehse.d etailed
descriptoifoa nlsg oritahnmdst heiirn teracwtiitohtn h eu nderlyihnagr dware
turan c omplicastuebdj eicntt soo methivnegr ya pproachaTbhliebs.o oki st he
perfeccotm paniotnoh avea ty ours idweh ilwer iticnogn currseonftt wafroer
Windows."
-JasZoann dGeern,e Mraanla gVeirs,uS atlu dMiioc,r osoft
ConcurrPernotg ramming
onW indows
Micro.sNoEftTD evelopSmeernite s
JohMno ntgomSeerryiA,eds v isor
DonB oxS,e riAedsv isor
BraAdb ramSse,ri Aedsv isor
Thea ward-wiMnincirnogs .oNfEtDT e velopmSeenrtiw easse stabliins2 h00e2td o p rovipdreo fessional
develowpietrthsh em oscto mpreheannsdip vrea ctciocvaelr oafgt eh el ate.sNtE Tt echnolIotgi ise s.
supporatneddd e velobpyet dh el eadearnsde xperotfMs i crosdoefvte loptmeecnhtn oliongcileusd,i ng
Microasrocfhti tMeVcPtsas,n, dl eadiinndgu slturmyi naBroioekissn.t hisse riperso viadc oer ree souorfc e
informaantdiu onnd erstaenvdeirnyg denveeeldotpsowe rri etfef ecatpipvlei cations.
Titlients h eS eries
BradA brams.,N EFTr amewSotrakn dLairbdr ary JamesS .M illearn dS usanRna gsdale,
AnnotaRteefde rVeonlcue1m :Be a sCel aLsisb raanrdy TheC ommoLna nguIangfrea strAuncntoutraSett eadn dard,
ExtenNduemde rLiicbsr 9a7r8y-,0 -321-15489-7 978-0-321-15493-4
BradA bramsa ndT amarAab rams.,N EFTr amework ChristNiaagne lE,n terpSreirsvewi ictethsh .eN ET
StandLairbdr Aanrnyo taRteefde rVeonlcue2m,: e FramewDoervke:l oDpiisntgr iBbuustienSdeo slsu tions
NetworkingR eLfliebcrLtaiirboyrn,aa nrdXy M, LL ibrary, wit.hN EETn terpSreirsvei9 c7e8s-,0 -321-24673-8
978-0-321-19445-9
BriaNno yesD,a tBai ndwiintgWh i ndoFwosr m2s. 0:
ChriAsn dersoEns, senWtiinadlo Pwrse sentation FoPurnodgartaimoSmnmi anrCgtl ieDnattA ap plicawtiit.ohNn Es,T
(WPF9)7,8 -0-321-37447-9 978-0-321-26892-1
BobB eauchemainnd D anS ullivAa nD,e veloGpueirtd'oes BriaNno yesS,m arCtl ieDnetp loywmietnChtl ickOnce:
SQLS erv2e0r0 957,8 -0-321-38218-4 DeployWiinngd oFwosr mAsp plicawtiitCohln isc kOnce,
Adam CalderoJno,eR lu mermanA,d vanAcSePd. NET 978-0-321-19769-6
AJAXS ervCeorn trFool.rsN :E FTr amew3o.r5k, FritOzn ionw ithK eitBhr ownE,s senAtSiPaNlE 2T. 0,
978-0-321-51444-8 978-0-321-23770-5
EriCca rtearn dE ric LipVpeirstuS,a tlu dTiooof losOr ff ice: StevRee snicRki,c harCdr aneC,h riBso wenE, ssential
UsinCg#w itEhx ceWlo,r dO,u tloaonkdI, n foPath, WindoCwosm municFaotuinodna Ftoi.roN nE:FT r amework
978-0-321-33488-6 3.5,978-0-321-44006-8
EriCca rtearn dE riLci pperVti,s uSatlu dTiooof losr ScotRto beratnsd H agenG reenD,e signFionrgm s
OffiUcsei:nV gi suBaals2 i0c0 w5i tEhx ceWlo,r dO,u tlook,
foMri croOsffoifIctne f oPaantdFh o rmSse rv2i0c0e7s,
and Inf9o7P8a-t0h-,3 21-41175-4
978-0-321-41059-7
StevCeo okG,a retJho nesS,t uarKte ntA,l anC ameron
NeiRlo odyne,X tre.mNeE IT:n trodeuXctirnegm e
WillDso, main-SDpeevceifilco pwmietVnhit s uSatlu dio
ProgramTmeicnhgn itqo.u NeEsDT e velopers,
DSLT oo9l7s8,- 0-321-39820-8
978-0-321-30363-9
KrzysztCowfa linaan dB radA bramsF,r amewDoerski gn
ChriSse llasn dM ichaeWle inhardWti,n doFwosr m2s. 0
GuidelCionnevse:n tIidoinoasmn,sdP , a tterRnesu sfaobrl e
Program9m7i8n-g0,- 321-26796-2
NETL ibraSreiceonsEd,d itio9n7,8 -0-321-54561-9
JoeD uffyC,o ncurPrreongtr amomniW nign dows, DharmaS huklaan dB obS chmidEts, senWtiinadlo ws
WorkflFoowu nda9t7i8o-n0,- 321-39983-0
978-0-321-43482-1
SamG uckenheimaenrd J uanJ .P erezS,o ftware GuyS mith-Fer.riNeErIT,n ternationalization:
EngineweirtiMhni gc roVsiosfuStat lu dTieoaS my stem, TheD eveloGpueirdt'oeBs u ildGilnogbW ailn dows
978-0-321-27872-2 andW ebA pplica9t7i8o-n0s-,3 21-34138-9
AnderHse jlsbeMragd,s T orgersSecno,t Wti ltamuth, WilSlt otatn dJ amesN ewkirkV,i suSatlu dTieoa m
PeteGro ldeT,he C #P rogramLmainnggu aThgier,dE d ition, SystBeemt:tS oefrt wDaervee lopfmoAergn itTl eea ms,
978-0-321-56299-9 978-0-321-41850-0
AlexH omera ndD aveS ussmanA,S PNE2T. I0l lustratePadu,lY aoa ndD avidD urant.,N ECTo mpaFcrta mework
978-0-321-41834-0 ProgramwmiitnChg# 9 ,7 8-0-321-17403-1
JoeK aplaann dR yanD unn,T he. NEDTe veloGpueirdt'oes PaulY aoa ndD avidD urant.,N ECTo mpaFcrta mework
DirecSteorrvyPi rcoegs ram9m7i8n-g0,- 321-35017-6P rogramwmiitnVhgi suBaalsN iEcT ,9 78-0-321-17404-8
MarkM ichaelEisss, enCt#i3 a.l0F: o .rN EFTr amew3o.r5k,
978-0-321-53392-0
Fomro rien forgmoat toii nofno rmit.com/msdotnetseries/
Concurrent
Programming
•
••
onW indows
JoDeu ffy
•
�.�A ddison-Wesley
UppeSra ddlReiv eNrJ, • Bosto• nI ndianap• oSlainFs r nacisco
New York• Toron•t Moo ntre•a Llo ndo•n M unic•h P ari• sM adrid
Capetow•n S ydne•y T oky•o S ingpaore• MexicCoi ty
Manyo ft hed esignatuisoendsb y manufacturaenrdss e lletrods i stingutihsehip rr oducatrse c laimeads
trademarWkhse.r et hosdee signataipopnesa irn t his baonodkt ,h ep ubliswhaesra waroef tar ademacrlka im,
thed esignathiaovnebs e enp rintweidt hi nitciaapli tlaelt toerri sna lcla pitals.
The. NETl ogios e ithae rr egisttreardeedm aorrtk r ademaorfMk i crosCoofrtp oratiinto hneU niteSdt ataensd o/r
othecro untrainedsi su sedu ndelri cenfsreo mM icrosoft.
Thea uthoarn dp ublishhaevrte a kecna rine t hep reparaotfit ohnib so okb,u tm aken oe xpresosrei dm pliweadr ranty
ofa ny kianndd a ssumneo r esponsibfiolrei rtryoo rrso missioNnos l.i abiilsai stys umefdo irn cidenotrc aoln se
quentidaalma geisnc onnectwiiotnoh r a risionugto ft heu seo ft hei nformatoirpo rno grams conhteareiinne.d
Thep ublisohfefre erxsc elldeinstc ouonntt sh ibso okw heno rderiendq uantiftoybr u lpku rchasoerss p ecisaall es,
whicmha yi ncluedlee ctrvoenrisci oannsd /ocru stocmo verasnd c ontepnatr ticutloy aoru rb usinetsrsa,i ning
goalmsa,r ketifnogc uasn,d b randiinngt ereFsotrms o.r ei nformatpiloena,sc eo ntact:
U.sC.o rporaatnedG overnmeSnatl es
(8003)8 2-3419
corpsales@pearsontechgroup.com
Fors aleosu tsitdheeU niteSdt atpelse acsoen tact:
InternatSiaolneasl
international@pearsoned.com
Visuisto nt heW eb:i nformit.acwo m/
LibraryC aot/aCloonggirnegsD-sai tna- Publication
DuffJyo,e 1,9 80-
Concurrent progroanWm imnidnogw /s J oeD uffy.
p. cm.
Includbeisb liograprheifcearle nacnedis n dex.
ISBN9 78-0-321-4(3p4b8k:2a. -l 1k p.a per1).P aralplreolg rammi(nCgo mputsecri ence)
2.E lectrodnaitpcar ocessing-Distprriobcuetsesdi3 n.Mg u.l titas(kCionmgp utsecri ence)
4.M icrosWoifntd ow(sC omputfeirl Ie.T) i tle.
QA76.642D28040 8
005.2'75-<1c22
2008033911
Copyrig©h 2t0 09Pe arsEodnu catiIonnc,.
Allr ighrtess ervPerdi.n tiendt heU niteSdt atoefsA mericTah.i psu blicatiispo rno tecbtyec do pyrigahntd,
permissmiuosnt b eo btainferdo mt hep ublispherri otroa nyp rohibirteepdr oductsitoonr,ai gnea retrieval
systeomr,t ransmisisnia onnyf ormo rb ya nym eans, electronic, mechanical, phoortl oickoepying, recording,
wiseF.o ri nformatrieogna rdipnegr missiwornist,te o :
PearsEodnu catiIonnc,
Rightasn dC ontraDcetpsa rtment
501B oylstSotnr eSeuti,t 9e0 0
BostoMnA, 02116
Fax( 6176)7 1-3447
ISBN-1937:8 -0-321-43482-1
ISBN-lO:0 -321-43482-X
Texptr intiendt heU niteSdt atoensr ecyclpeadp eart E dwardBsr otheirnAs n nA rborM,i chigan.
Firpsrti ntiOncgt,o b2e0r0 8
For Mo&m Dad
•
Contenattsa Glance
Conettns
Xl
Forewxoirxd
Prfaecex xiii
AcnkoewgdlmetnsX XVll
AboutthA eut hoxrx ix
PARIT Concept1 s
1 Introduction 3
2 SynchronizaantdTi oinm e1 3
PARITI Mechanis7m7s
3 Thresa d 97
4 AdvanTcherde sa d127
5 WindowKse rnSeyln chroniza1t8i3o n
6 Dataan dC ontrSoyln chroniza2t53i on
7 ThreaPdo ols3 15
8 AsynchronPoruosg rammiMnogd els3 99
9 Fiber4s2 9
PARITI IT echnique4s7 5
10M emoryM odelasn dL ocFkr eedom4 77
11C oncurreHnaczya rd5s4 5
ix