Os Unit 2

You might also like

Download as pdf
Download as pdf
You are on page 1of 90
SEE! >SSOCFEOCTEEEFEUCECCECTEEEKEEGEEETEEEE df UNIT-oTr 4 The. Objective. D malttprog wamming (se ko i — re | Tmaniniel CPO utilaetion. [hae some. Procaas ‘unning ; at all time"] 6 Usa. kinoe_ Produc Processes are kapt tn mamory ak one. time. . Whar, Vp Or™ PYece2S hex to coall, the. parating - ays ane Pron bhow Process And given tha. CPU to | another proms, i LOPU-Tjo Burst cyte: SST Cie ee: * Procass exactution. connists qa exycla. 4 CPO eacution anef i Clo wait Procassay alkernate. belascen these. 2 States. i | Procase tion bagins with a CPU burs. followed by fen To burst ebon-anotsix CPO Bure | thon “anothas | : [Slo burst: the ‘lac cpu bure will end-cith a Ayplre TaqHeL | To barminate execution , i 1 1 Ae tlo bound Prograns haw mand vamy shoxk CPU burst, . |" CPU bound Progran haw. a fow vas long CPU burst, [. i 5 ; Scanned with CamScanner Alkaxnating _ Aaguence 4 CO — re s cpu burst add Ato. - vaad Prom fila. ae 40 bara —_———___——— woik for Tlo Tlo bust ~ Stora. increment inlen. cpu burst vorita. to fle load Atova add Atore. CPO burst read From file walk Jor slo glo burst en | [oat for Tio | I To burst | ‘PU Scheduler : pa shenaver ha. CPU “balcomes calle. , eho operating Agpseam “rouse eleck orm % th ptocassas in tha. Waly Qquena EO bo mocutsd: Tha. salaction process is carviad out by eho hoxk-taxm schodulav.(or CPO schaclular) - ce Achaduloy Aelecks from among tha processes in parpory that ava Fandly ko axacuta, and allocakes tha PLU bo one G them. Scanned with CamScanner _Nonprersptive. chad 4{0nea tho cpu hay baan jallocakacl to a Process | ube Process keaps tha cpu until ik Telearar tse CPU oikher by barninating. oy b Orca. a fepy has been Allocakad to.a process, beton | ikS Completion. ome. other prrocass can. bo. alllocalad “to cpo econ) i Ha umaiting tata. CReunptancer for non-praamptin: | circumstances for ‘Pre eroption : sWhon 0 procass Aeaitches Pom tho FePning Akaka. bo the woaiki A : yp ang Atata-('e3: tf requ) + Who a PTocess bayminates + Whan a process switches fiom ha. vunnng stata bo “ads Avato. (fq: 4oereupk occurs ) slobon a procass switchers Prom | woiting Atola ko Twadiy stale (£9! Complation 9 alo) Dispatchar: a] Dispatehar aivas control @ tha. by tho Ahork- barm — echodulex- af This qanceion involves : CPU Lo tha. procosss falctad . Awitching * Contant . switching to user mech + Jumping te cha proper location in tha user Ptogiam ko restart tha, P%OGtam ob process ancl = Auat anothor thoning, ts known ad dispatch. latency - say Scanned with CamScanner \ ie kakes for tha chispatchey ko Akop | \ i sree entre iptemne ce reneeel°g The evitarins cach {or choosing algorithms ara. ? + CPU VEiligation. + Mhroughpat. + Tammartound bime. + Waiting tna. + Response. timo Po_vbiligation: reap Ee CPL as busy ab possible. 5 e roughput: . - roughput completed PO f Tbrougbput 6 Eh pumber % promsse® j unit kirco+ umaround tina: . \ rHow leq ik baka to eiteaea thak 4 The interval from Hime “q submission g kima gq wrmplauion is tle carnavound &im ; 4 dt iS tha sum g. paritde spank waiking EO gee" wsoiting in ta ready apie ,exzeniting On cpu. &-doing tle . Seis tho am. posiods Apant waiting iD tha. Tmady Queue . Sponee. kime: y \ Ie is tho viroa/“ fromm the submission ga vaguest until kha! free oxponin. iS . Produmd- $e 1S tha Qmounk bi jk Laks to start “espondling but. Rok eho cIMe that it Fakes to oukpuk Eh ‘Febponsa pls ramoy , Maximize CPL utilization and tbroughput - Mininoiga. Eurmaround kina, , salting time, and WAPoNDA. cima . Scanned with CamScanner NG ALGoRITHMS 1 CPO Achacluling dials with tha. problem 4 aleciding chick, ; : q Ha. procesces in tha. readsy qpiaie. 16 to be. allocated : tho. CPU 41Tha varv?ous Achacleling algonithers an \-5 First -Coma., fivak -Sarvacl ScRoculing + D> Shoreost -Tob - firs AeRactaling ' : : > Priority SeRacluling i = Round -Rebin. SeRadlling > Multileel Queue Schaduling > Multilevel Joodback Quaue Sefedling 1?! Aine 7 Corme “inst- Servad Scheduling: (Fcrs) \ Tho. “procass thot rqpuats tha. CPU {first is allocated to | khe. cO fivet ~ | \ Tha. implamantotion g FeFS policy is ith a Alo quem . 4 ° “ moro - | Whar a process antays’ tha ¥ Queu. its Pes | linked onto tbe tail % the Queue - When the cpu is free _ ik is allocated to the The. Tanning process 15 thon yemovacd “from tha O4eU0, \ procass ak tha hood % tho, Quace. \ | Adhantag: + Code. 16 pimple ko write and undesetand . Scanned with CamScanner example 50's wing Bak Cee : ; spnsidar — Uho- follow ng, im purst Urea. Giver Ce dima. with the length J notllyaeconels ¢ : Process Burst, Tine, “Pp lg. i Pa —- Ps 3° Pi, Pa Pa ard or fuse processes asia io tbe order o somad in Fers onlay, Gantt Chart: i cRachule . 4 is a bor chee thot illuseralze CPO * tpok arrive. ab V, Pl [ee _| P3 ° waiting Hime doy op, . = oms Pa = dims P3 =.ATms - Avusroge., waiting tima = (o+ 24 +a1)/3 aan ay aT 30 =lTms £ the process arrive. in tha. order Pa Pa, Py ePan [poy rs | Pi ‘ ° 3 6 30 \aaiting tia dor | Pi e6ma Pazoma Paz3ma Avuage waiting tire - (6+0+3)/3 7 3Bms Scanned with CamScanner BD |Drawback: > o | 7 Cepveg effect lowirs CPU anc device. utilization D D [convoy of fect; > +All othoy procassas waik for one. big prowess bo Get ' | off tha. cpu >! > * FCS Achaduling dliotichms is non-pramptive. - | 4 is - Lroublasome for kiran, -Blhating. ephams 1 de | Shortest -Tob Airst Schaduling : (s3F) LH Each process iS Asseciakad ithe. He. langth. 2 the } lattax’s next CPU burst - | Whan tha. Cpu is auilabla., ik is assignad to tha. procass that has the. Smallest next CPO burst - | Af a processes haw. Lhe sama. langth nant CPO burst, than .FCFS ‘seReduling is wrod - | i i lexorople.! ndiclay = Eo. qollewing Ark 4 processes ,usich tha. langth | i Col q Cpe burst time gevan. cr melltsacords . Process ures. Tina. 6 Pa ‘ ®; 1 Y, 3 Gantt chart: Pa Pi Ps Py ° 3 9 ie oy Scanned with CamScanner waitir 5 time. fos 9, = 3m Ps = Ioms Pa = Am Db, 2 Om . A. Avorage. waiting kira + (34164440) /4 = hm + dk is optimal (qWvts mipinoum avestogp. waiting bime) Drawhack! -difficule to know tha. langeh q nan CPO erage Approxinoalz. SIF schachibling > Practice tha naxk CPO bust 2 we axpick bak naxt CPU buat = previous one’s i6 Airmilax in fang the bo po park CPU burt 5 prackectad od an. oxponantial avarage the maasuract langthe 4 praviows cpu bursts Lok bp ben.. tha” Jangth aq, nth ope ie “1a ee ae practicead Valus_ er naxk CPO burst rh, 04 KS1, dafion ehe exponential ave7age [Puree reen], kn contains uy rose weeank éMformation Tn skoros cha- past Restory o& controls the volativa. wouight J vocank & pare” Rubleony en. our pradk'ction 4S h-0,kban Toy > reconk frototy fos no affect SF oezt, then Tay ck =) Mest Tacant CPO butbe makkars Scanned with CamScanner Tea SIF algorithms ray be. either preamptiva. 0% nonpremplme|t 7 ~-4itsk Pranmptvo. sc ia eal shorbesk- remaining - Hoa. -4i72 schaduling « Shortesk -ramaining. tima..4remt Aebacling: Example: Consider tho. following A processes with kha. fongth 9. ( kha. CPO hurak kimea. given th: roillisaconds! ‘Proca.ss Arrival Time. Burak Time, Py 0 a4 Ry @ Pz a q Pe 3 Ss Gantt cRare: - [of Ps 4 m | \ ° i s lo m Qe ‘Waitiog elfen. dor ®. =: Cto-t) = @ ms ‘ Pas lel 7 ord P3 Mea 215m Pa 25. =A ms Averag, veaiing time. = @toris +a) 14 = &S ms ———— Scanned with CamScanner ent Soci A priovity ja assecibtocl is allocated to foith each pracass ,and CPU tha, precass with frgParte pesorityy . Fapal -puiorily pavce saan ara. Ackacdufecl yy FCS order Get —Peonily yy Zaample.’ Ponsioley the followsin arrived J Aae 4 Procasar armemad to fava. OE UM 0 te fa order Pi Py... Pre with tha, langth. % eh CPO: buat Line. Given in millesoronda : ‘Process Burst Tre Priority ?, 1o 3 Re ! 1 Ps 7 A Py , Pe Ps 5 a ‘ mi | Pi | ?s le, | oo 6 clo Ms Lg dating bina $r Pi = om . Pag soma Ps = 16m Pr = 1G ma Avera waiting ima. “Groriene)] 4 kam | i i / | * ; Scanned with CamScanner ~TewwwwewuvuvwvvvvvVvZTVwTVwTKwT wT wv wT eT ww rt | ’ | ! 1% Priotitixn cary bbe. dlefinadl aithar . intasnally + axtarnal Iy “eterally datined pvt, 1050. some maasevable- autanuly or Quankitias ko Computa_ tha priovity qa procass: FQ! kima. Dinites sya roony roquivananls ,rrstohor | open. flo * ae by enitesia Laat ave. oxtemal to tha. opesrcing ftam « FE reportane o promss, type carne fos bang pal ad cempukey Ua. Priority schaduling can bo. *Preensptive. CPreampe cpu if priowly. q nau proces is Reghar than. cure: process) + Nonpreansptiva. Prowhack: . - sindefinita. blocking (or Skarvation) A promss that is ready totun but lacking Cpu ke considered blocked - A priotitg sehacusbing algosithes leave. nal lows - priovitieg process eociting todlefin italy er cpo. Aolutio ts Atarvation vs aging - Aging ‘is a technique. 4% Grodualley inemating tho pricnity g — proca.s2ay thay, wie in kha A4ysbem Hr a j Pong imma Xv Scanned with CamScanner Round — Robie (RR) Scheduling : fe is dlasignad jor Hea. Sharing, Aiypiams « : bis similar to FERS scheduling , but preampkion is addad zo Awikch bekwaen processor 1 Amall anit q time. callect a binge. quantum (ov tima. Alice) 5 dadinad - (10 to toon’) The wrancly queue. is trata as Q@ circular guna. proass 5 longer Mf tha. cho burst 4 cartantly Tune ‘. ge off ard will cause toon + bina. dant, the. tiroar will \ jnkerrepe to the opmrating System - A contark ausitch_ bo. axtecutad ,and tha. process will ba put ab the Eas! aill Eha. voady Queue: The. CPU Aadularx will Aclack tho f roxk process ‘in the. maadsy queue - tho. followin, Ack G% procjsses thal. arrive tons ile E kime 0, wikbh eho. length 4 CPU- barat time. in milliseconds : Burs Vrre. Fino quantum +4. ms Procass ore Pp Che L Pa 3 ee, Pe 3 ~ + ee py a | | pe | Pr | Ph to 14 18 a ae 30 Waiting - kima. fer Re o-4.-6m> Pas 4s P32 1m Aveioge woaiting tiree. = (6+44+75/3 ~ 566m = Scanned with CamScanner * Rounel Roben. sefaduling & proomptive. ) eu, Performann. 4 PR algasthm dapands on. Aigo. q ima. wartere . = «IAP bine, Qpontun is vost, large. pp foloy és Aama on Fees policy. . x AP time. Awantary iS vous Arnall, RR approack is callacl «PTOCO Scar Ahenig 4 gp Acflesar. oo. Afesilal Censiola.n tha. o-ffack Correactts aeoiteh hg on. Ue parformanta.. % wR acBaclubing Fa: Sfowiog how a _aroalley tine. quontius incrodes tontark witcha p——Tesst tiesto ne an —— fa ° — 6 1 ° to | { T T | \ | | = | i i nr 4 mH Aituation’s , asoups qr A Commen ol’ (or. interactive) +, Foraground proce beckawourd proca ee Scanned with CamScanner Multilave! Queen Achactuling algorithm por kibions Ea reock Queue into Aevazal Acporab. quasies- highost. patority SS __Aystans precascen|—> [intact bg preana]—> Pat [> co|__ sen proeamaa JS lowest Promila “HQ! Multilevel oyiaua. sefaduting Tha procassa aro. paxrmanantly assiqnid to ona. quaua besecl on sence Propast] 9 tha process Auck.od memory Rigo, process puorily arc, { Zack pave far its oun pckectuling algotitBin Tho foreground ape is Achockloc ky RR algosithm L i backyound queue. is Achadulacl by CFS algosithm . 4 mulblevel quene scheduling Lal gotcha has 5 Guus. | > Apkem processes 7 ! a §rtaackive. processes { = 4rtarackiva— ackitcing, processes 2 Batch. precassed > Student: Ptocassan queue. har absolut. prionle var lower - priouity > both quew. eoald van unless tha. queues 1005504, |PEagacKiA. P¥OCeSseK and inkatackite_ 50 -wara all amply ~ Scanned with CamScanner [PRocess— Syncneoni zation] |" *) Conecrrant access bo Alwmed data Fosults in data incomistng) *1 TO onserna orderly) esaceition. 4 aeeeeeed Processes Uek aha. a logiaal adelvass space.,40 data consistancy & taiintained - * dn Ceeperating PTOCLSS , Uso olution ko prrocscns-comurnay Him allows atmest. BUFFERSIZE -1 items in buffer at Pro Hows: | | tho Same bima. | | | | Ora. possibilty bo emacs this drawback is to add an | We BAL Variable. counter initialed to o i + Cantar is"oeramantad esban. wa odd a nas item to batter | rCoureer is dactamaentad when wa ‘‘arove ona. itam fiom buf | leeeees i | Rode tov producer process ee for conburses sites heey whileci> | Teproduce. ors ikem in neatpuoduced x [\é bili. (Counter 22 BUFFER size) 3 1d6 nothing » / next contumed = buffer (out). i buffer J+ pextproducad - Out = (out+1) 7, BUFFER_sSiZe ; in. (41) ZBOFFER size 5 Counter -—; i counter ++» 1 Peonue. tbe em in. eatzordne a } qi | The outioas (code. nok feration. eorractly chan 9-2 coal Cepcuvrenely Scanned with CamScanner KOO . : Sup 1s nt ~ FF Suppose. counters s.% producer ancl conmuaer process execute. tha. m Akavannl counter t- anck Countas-- Cencurmantly : d Ww0 can. 4 eRPact: Value *. 4,5 ove (Aneoret.) 4rophmentation. 4 COUNT ecUnkax — — in machina language = Counkar + 4: counter agestay, = Counkey Testor, TeMBter, = countes ® Yaqestas, +) Venistor = Tagseary ~ | = Teast a counkox aquster, Counters ‘register, Tha. concurrant execution FG Coureart + ancl counter _* is eguivalene €O Q Acquantial exdce Won eh, one! Aentaroants ava. inrtarleavad in soma. orda. . To: Producer i= etecuke waster, Foy fregistas, 254 T, 2 producay exacts. vagistor, Pragestar +1 {magester,=6 4 Ta: Conscnoasr emecuin. — registers = countar frgisers=s} Ta :Comumay - exacube — -mgistory.= raqishara! freqisters=aY} Ta: ptoduca, axocuta. counter = Yeo'stor, {counter 6h Ig: Consuroan + oxeeuke Counter. raqestany feountors 4.4 2 doworrck plate [correct Blake. counter 75] 3ce._ Condition: . y@ (jererel Procassas aceass and manipulake. tha. same. data Seeurrently Ad tha. oukcorna. q the execution. deparcla on bo Particular order in which acts takes plata. calle rac.cordiben Scanned with CamScanner yy ack process fm a Aaqmant 4, code. callad cxitical Aackion in cokich a (procass Mar] ho Changena, common. Variables , ed a table. uotitig a { Io. 40 On: eateeiqies: ; The 6S proplans is to lamign a protocol that kha. procaseas con use. to cooperate. Gonaxal seructure 4 procass Re % —_-_—_—_— 1 { | 4 the. action @ code. eshacra emery Aaation | Critical peccion the prociss musk requee pasmission to enter its cHtcal Section. i's ankwy ‘action * The ctitical saction js pllewad by exit ALCL Ion. amie sackion| Yomairddr raction 4 while G1); A olution to cxttieal section problam rouak Aatisly 2 teqpsiemants + Mutual Exclusion? 4 procass p; is exacting ip its critical Anction, than ho other processes + Progiess: 4f no prenass is axacuking in ike Critical Aection ‘and ome can. ba. axacuting in thaer critical Action. | proassa, wish to entax their critical Aackions, then ool those. processes that arp. nok axacuting én thar remainder its cxlscal sootion naxt,and this Aeleckion. cannot ba. { I | action. can porticipata. in decision on which will entir — | i postponac inde.fioicalg 4 Scanned with CamScanner Them orig @ bound on the number kimass thak othox cass are. allowed to onar thar exitical pha 0. sactions after a procass hak moda. to agpank bo entar eaitical section ane bo {oro ho. rocuont. 16 grand TWO- PRocess SOLUTIONS! motes SO rOTiONS Consiola® ot procas Algorithms he Pe and Dy lo e [bile Cea ]= 35] IAP not t's tear pasate indefpitaty Jloftax é laavan evitical Aaction ,leks J anos TemMainder AdckIon Joohilals) 5 Reorentaes mutual exclusion. Doss nek Guatrantea FOG rats Hiolatar ountad wai Morita 3 lag ci ua 5 whi a-Cflaq C/I); critical section. [Siege | Jd whilecn); Mrtady to ontes cs II 4 | want cs, then ¢ Ahould wait lofie, ilaove% C6,lek j in TaMaincesr 20¢bion Scanned with CamScanner *M “ual Exclusion is satis fiad af PagciJ Flog (JJ is tua, both ie dr WSs t IS nok mal mt cy roae PEEP loop. forarar] ! { Algovitho a: (Perarson's Algorithm ) user a variqhles Abared batucon- plocasen boolaan. flog (212 ine turn | ildo | i Flag [vj =tro0. 5 Ii (Sredy bo anter cg I {| tarney 5 lat: irke cs i wobile CFlagti] 44 eatbea: Mar j wones og & J 6eb tom to}! pe ee eitical s0ckion_ yp > COUN SEOe Tomaindes £2LbOn (e | ! | than i bas to wait Yesbilacy 5 Satis fos + Mutual Fxcluxon ! . Progress + Bounded wait “4 Scanned with CamScanner Matkipte. - Procass olution. (Bak a Niqgorithin): pte le a area ece mt Nigonitha ) de solvas critical Aaction. problem rn. prot 503 ge is called baker algorithin bacauso. it i6 boxad on a Achoctaling algorithm arocl in bakotan, shores ake 09 ercaming the Atore.,0ach customer sacs’ a purobas +The. ccastomat with foworxt, aunnbos, ia Aamad paay.. NO 2 processor Akoutcl eA. AGM. HaMbyA . i Dl se sbho. proces with our02. name. i ,Adxved or at Toa. data trucks ara. - | boolean eRoosing (r3 ; | IDE Pumbar (nj: } oa cla fina notation ¢ + (a,b) M90 Ubreugh ll procaccas { while. (choosing [i } Wusdba. tore to ore. ic currently wine vat nmi © while. ( Crumboay (J 12038 & Curobaa(h J 4 \Chatackasistic ’ ¢ This invetruction is enecetocl atomically 7 4 4h a TarkMnbS2k imeractions ave axtacotad Aimaltanaoualy khoy sill ba. exaccitcact Aaquartilly in Soma, orbittany oda Scanned with CamScanner Mutunt ExcLusion Implementation With TestAndset Critical dection | jLock =farse | -yemaineder Section J whiteods Compare-and- Swap dasérauction Acpinition a Ent Compare-ancl- SWAPCént Rtarget , int Leap, Ent key) t a : el jfe | lan l. CTestand see (toce)) 5 | | | | | | | | | | | i \ unk Lemp = targets Lome | Lpleargee cs e2zp) dangee = KY: | i \ yeturn bemP> jarce A! Mutual exciusion Impiementation with Compoyre_and- swap oo i ° 0,1) while (compare anc— gwapl Lock 5 ’ critica’ Section Lock =0; vemoinder section Jwhile 1); Scanned with CamScanner [SenAprones a isa Aagnelsonipation tool usod to fied polubions, ~ complex Critical Aartion prroblon. A Aamaphora. S is an intogar variablo, kha is aceessc] Somephos Kbvough @ Akandard oparations ; seaik [DP from Dutch. prrobecon to best) “Aigoal [LV, Prom verkegan, ,b0 dnensoont’] Used whor a Procass yanks 4 accass a TenoUTe, . wark CSD eq: Making in. t while CSzo0) rermaplone. 7 Total tants -50 3 leo op S--: iP one. pascon arrive, - ° saating dactiases (s,5-J | Whar ron copecitey 5| wenchad , Seating 0, gf 2 pemon learcs, Aoating (dere (50. s4eJ kWhan che procass medifixs tha semaphore. value no other process can Brnaltaneoubly modify that sama. semaphoa. val { i a Scanned with CamScanner Usaga_: usage: Semaphoras ave. aml to deal qith P-procass . critical -saction. swolslan he, sl PP Peesms — Sham a Amapherw. mata Mutual oclusion) initialigact to | Matual axctusion ime tion. with Larmaphorer, Aiqnal Cmutox) ; | TAMaAIinolar Aackion Jesbilacry : emaphoves can ba: used to Aolve” synchtonigation problems & { roridexy A Copcervvantly sunning processes : Py aaith aq Atalanank sh mutox) 5 | critical beckion. | ! i i i i { t wd Pa with @ Stakimant %. Suppose wo. waquite that Sa be 2 oxsented only afar $ has compleked - P, LP shaw a rmmon Aumaphota. .ryrch, initialized to 0. S15 | a, jn | Signal (syach); \ exait rock), Ps woplarmantation: : 5 . pie ie EEE, bo disadvantage 9 Mutual axclusion Aolutions is “busy waiting. Buty waaiting, wattear CPV cyclers tha& 2Ona. other process uso. productively this eypa. a Asemaphow | epi t (piecat spin efile waiting for lock) | Scanned with CamScanner Advantage 9. spinleck | SPO content AtwiteR 1S vaqpivacl- 4+1To overconse_ busy walking, mocy dafimtion 9 unit gna] . sWhan a process exacator tho wait operation and finds that tha Aamaphore. valu. 16 Pot PosibiVE, iG mud wajk. ~ Rathax thon busg waiting Jebe. Process can Mock itself. Block Oparation—> placos a process (nko tq iting quene_ ban , corer! 1S eransfarnd to CPU Achedulex , which AUetes anoticar puocass bo axacuta « A blockacl process should ba. “weatartad whin rome obo exactikeas a aégoal opviation. 5 | } t | prtocass droplumartation g bemephors: "oo" Seruck: eos typedef Struck : tfach mraphaa: bar a | £ tre value; - ineager valus. ard list SeTuck, pxOd-SS ¥L: = q process + 4 aorcaphore + i iE ord! ! ott OR: . aignal oparation: void waik(Semaphore«S > void aignal (Aoroaphore#s)) © syvatua--5 f Syalue +e; if (Sevalue.zo)d ef (Swalue.<=0) f . ; , . add thie process to Supt Dern proass ‘P block); : . y 4 : From SeLigh 1 wa kayp(P); 1 Scanned with CamScanner Binory Seroaphores: A binary Aamaphow. is a Valua. tisat. can ange. onl between 0 to 1 tok S be a counting AoIMAYpshore. + Data Akwetures! ArMaphorw. - with an incaqer binaty- Somaphor. S1, Sy ; fk C: Initially 2 + j d- SIF, S80, c= initial Value g. counting Larsaphove. 5 Aigpal Operation: wait (51): C++ if(c2o) if (c<=0) t signal (6); alse Signal (s1) ; signal (s1); waik C2); 4 signal (si); oo Scanned with CamScanner sess areas becinare » ee » SIC PROBLEMS OF SYNC HRONIZATION | e se ee »’ Samaphor> are. usocd for Aypebsonization in our Polubsons > fra lage. claw q coneaione -tsntxol praoblem » + Boundod ‘Pal'for Problem S + Roaders. writers — Prcblaro > . Dining = Philoscphars problan 0 » » | Bounded - Buffer Probkm: ® 4 Assure. a pool gq nr baffers, each capable. 4 folding D- | one ikem - To allow producer and Consumer Procassa tO Yun a buffox + ikams that can he filled concurrently , hava by producer. and amptiac by corburoei Aamaphoras ad are * mukex > provides mutual exclusion for Qcassas to buffer pool. > inieialigd to 1 + oropl ~~y~wwvewy: > count Fhe number g eropty buffexs -> inittalizod ton + full > count umber q full buffers aS initialigad ko 9. r/Erepty Counte is decremented when a naw ikem has pul ing, buffar & fall 1S incaementad whan ié iS Consumed - 4f Eps produce, Ems bo claewement aropky count while, * ies volun ie pee cha. Producer ' put to Aleop The next Fires. an jkam is consumed, arepti count is inctementid end producat wake up Scanned with CamScanner | seractare. q. producae process | Sevuctare q__prodlicas. pro do Bo, produce. an ikon in nexkp ewaitCansphit) ; Nehoek if thao. is any armply buffey cwaikCroutax); chock *f no oth prodaen is ae add naxtp oO tha. buffy argpal (mates ) : aignal (Fatty; Ikells consctoexs thot thas 6 ikon Jesbilecsy ; oa Strack. Consurcay gyrecass i -do : © coal Cfutl) ; Weback if thee. is any itn w0aik(mutex) ; Imako Aue. that no on cla fs wing ip ‘amove. an itam fron buff. to naxtc ( signa (mutex); Signal (empty) ; [4qGnal Producer to produce . Pend ions Corburma_ the. itans in nexte Gesbila. C1): Scanned with CamScanner x N data object Couch an a file. oF aorord ) ie bo ba. Aharad amon Aovoral cCONcUTTANE pprocassa . #] Some. promssar mac seed tha. contant. q. shan objtel Cactaas) a Upolata Coorite JME ot woaxtors accass Alarel data preulkere ously , x0 oFfeds wil oct. a] dF a “usritax ancl some. okber process aceass the. sharnc| oboe. seonlbara.oasl4 , confarion inoq aris. >) [Bist_veodars-usritars problem: *Raoders ar giver priovily No weader will bo. kopt awaiting unless a wrikar has alraacly obtainadl §paxmisston to uaa it + lrikerS may Abate. « | Sacondl, reodars-woritars problem: + [otibass are. giver prcority. a . Fa asvitax is esaiting ko access tha objeck,no mow teodos may reatk reading | + Readers moy Stare Aclution bo First wroadans - wtiters Problens: | datareractutas used : ! Aw | Sumaphora. mula , coe 5 ine recdleount ; ! t |proutan: oars. mutaal exclusion when rwadeount (sapdaed | | 5 inieialligad | wl. \ seaclesint*.»keaps txaek g how mary prowscos ave. comentiy reading | initialized too. "woe! > enarer wettual excluvion pk woritans Scanned with CamScanner wail: CAML) e ‘ Muaits until no other process is acces 4, lef writing is poxfornrsac} Aignal Gay \; Baiqnals efor. Anyons. osha waighan Con acces fe eola. jer Treader procoas waikCnoutex); toe wosteet D Il process walt anki! no.ora-.is occasHing ie weaclcounts+: process aad from fib. ifCreadicount = 41) era, - waik(es%t) ° Wif tha veodey is tha only ready acconing fh, : i. TE waits untils ang wsiitens fave. firided Signal (makox) ; Il ott processon rcs dae po to ee med ee ye Feadling 65 paxfornad waikCmutox )- [indicate taoding 1S dora. it waits until no-coe alsa is Aecening hak vation — voaolcount -- 5 [[dcerements radeoune 'F Croadeountz+0) I $F no other Teno aw waiti 7 to Yaad ji Aigral Usk ky veccky Or eotitar con. acasts Hath eqoal(ruteas), I[inchtalis it 5 olona. with Yeodkout- Signal (ote) ys Scanned with CamScanner ‘[Picing Philosopbars Prolelans; x| Consider ig philosophaxs who spend their fiver ticking andl 2akins 4[ The. pbilocephars bow. a common circular tabh. Aurrounclecf by 5° chains, sack. baloagng to ona. sphilosophar | deo tho. canto, q bable. a bowl 4 rico.,ancl tobk. 6 laich with 5 angi. cRopabiets « dlehan a philosepher thinks Aho clons nol ineasact esith Row Colleaguas A’ philorophax goes fungry and triaA'to = ap ted Aes that ce Clorort to far <{ Bho. cannot pick up a’ cRopatick that i's already in tha. banc} 4 a naighbour When @ Rerogry philosophar hax footh hax Chopsticks at tha Bama. time , Ako eats - without valeaning flor chopsticks Whos aha findhaol Paling Ska putcloun both ¢Papatick Aolution ! data berucku10— Aamaphore chopstick (512 initialigd b 1. Seruceure. ilesophar ¢ : do 2 ; pe wait Cchopstick (it); wait Cohopttick Leer z 5); eo signal (chopstick i] be Signal (chopstick (c+ 759); Lbink ywhile Cero); Scanned with CamScanner ! Romaclion to dlocdlock problem Allow atmast 4 philosophara Lo bo Makita ‘Alroulkanaousks at the. bab. chopsticks are + Allow 9 philosophox bo pick. up box chopsticks oly if both available. . » Usa, an a NL VO. A seyranaaterre — Aolubion. Ge an. octal pbhilosophay preke cpp frrate how lofi cRepatick. anol thon. Ras “alk. chopstick jeshowar on avan. “pRelasopha» picks up Ray right eRopstick arc thon foi late chapatict . Scanned with CamScanner dtis ag high Jawa feqochronigation comet: Moniter ia chavactaniyadl by fale of Proryraronan dlafinac| Operates. Tho. yeprarantation cs monitor by po consis 4 4 + declarations, 4, Variablos (:fote. values dines lake. ga" instancs} + boclion a pprecectiuey|{ynctions, (replant opasratcions on. te. type) Sypean 4 a. monitor | IMOnikoy monitor-name_ £ Shaved variable -ceclarations i procedure. body piC---)£ = j procedure body PAC >» +) teers ES j | procedure, hoody PoCee 2 i ft... 4 | t jo! ‘initialization. coda. A pwocadura dafinad asithin @ monitor can accaxs onl thosa variables dla.closacl locally within the. monitor Libs formal sparrametass- ‘The local variables % & monitor can. ba accessacl by local procaduras only « Scanned with CamScanner t— {tha meniter Cememct. an nua that ony ona prroca. @ ima. can ba. active within tha. monitor Abani) see ys ut Pr7abions FY Schemabvie view qa monitor wie Schematic view The 4 — - Yechroni zation. machanisms ata. provielad by conditfon_ construct . A proqramnnaa ako needs to write. kha aypchronization Schama. can detira. ona. oF mor Variables % type condition: Condition. my: ard signal 7 | | | | Fn : . | <[che operctions involved in a condition vatiabla. aya wait | / %-waikC): ~ Aubpands a promss | i Jf wSignal(); — 5 1a»umes a suapanded prowes «| 4 po process’ is suspended thon tha. signal opaxation fox no affect 4yuer Associated with ‘oy cond Tiga: Monitor with condition Yavelies Scanned with CamScanner a Drodllock - trea. Aoluben to lining -philosophars problaro; 0 2 Philosophay is allowad to pickup, Rar cRopatick, only if both, 4 Hem ave. available: > distinguish among RB Akaka in which philoso phox may be, > Paka skaactenas wad aw. : enum f thinking ; hungry , eating y state(s]: * Philosophey ¢ can sok tha. variable. atalil Ci]= eating only if her ao neighbous ais” hok gating : _ condition, olf [57° *| Each philosopher befor Akar ting bo dot must invoke Ere opagationy pickup: After” completion 4 tho operation | | philosopher remy at: Then, the. philosopher invoked a_ i putdown opasation ard oa Arowe tO think - 7 op. pitkup(e) 5 cat __ Alp patdocn(e) > AW distribution % Chopsticks is contsolled by the, monitor dp, --- we (stake. Fetasz SH zaating) ee (state [6419%5] | ating) ) 4 Declare. Scanned with CamScanner 31 moni Ths tor dlp enum f th condition. Aalf(s]; void pickup@nt ¢) © stave.ci]. buagny 5 kast(); 3 void Putdown Cine oOo t Voiol 3 olution [fone clenclinet occlu. fut a philosopher — mays A monitor solution le dining philotophar problena State [i]: ubioking hinking | hungry 1 dating y stata [5] if f Cotace (ey! seating ) Self (iJ-«aik ¢ vs : ; East (Ct44)75); bast Ccean7s)- kesteCink 2D if (CStaw. (atta) x53 |= eating ) A, (Abate [i] ==Rungry) ; Vb (stare. Ces] | zeatingyy § stawefiJ =aating ; SUuFCIT Siqnale dy Voi init) for(int e205 (26 iter) Stata. Ci ]= thinking - we ee : anus tht’ no a neighbours au eating (simul cowl Scanned with CamScanner DEADLOCKS A procosg requests yesourcen. Jf Kha. Tesousces AW The. sasources roquoatecl by khis enaiting Procoss are. held by othax esaiting processes “This Bi bualeion, is callad claadlock. oO FQ: When two tains approach each other at @ crossing, both will stop and neither will stave ogain until tha other har gore - SYSTEM MODEL xh ‘Bysearo consists gq ficito. Dumber g. YeSoirrcas ERak can: be. dltsetibuted among nunbaxr J competing Ptocesses - The. Yasourcas cr. parcitionad into Aaveral types fy: Marnory Space. cpu cyles Ailes Llo domo, Scanned with CamScanner ik Al . Ret available. , to. pprecass anters a waik AbAke. + Foch Eypa- 4 OHOUTCA— consists 4 ge. 4. identical instances - Us, then Elo. Yrsourca. exype aya a atptar hos 2 | “cpu has Q inttancas » Sf a process WHAALAOAES an instanc. 4 a tba allocation 4 any instance, gatiaty ha. TOQUESE - 4g it “es not ingeancas Ard hok identical, e dofinacl Propety , wOsOUICL. bape, Ehe “ Eype- will * patis sfying , thon Ehe. anol = yasourca. eypa classes ara. no &: A Aybeor hos 2 printers. Aoficad in sana vasouree. class > any printer pails any output ourca. clams > on. prinker tn gt Floor 2 o&hax Agfined in ~Soperaka. Ver ip qrourch floor. + A process reay anor’ a wsoutca. be joe oning iE and mast woleox ha. FTOUTCO- ofeox using e nok x Tha nurobet % eg bOUTLA reo.oyuortid reay utco® available in excood tha - Lokal nunbor % ee Scanned with CamScanner * Order permal moo. JF operation ja process able a yasource in only Elo. {plowing Aacysonce + I-Requost: : Of the. maquost cannot. be. Qpronted inomeciataly , than Eno. MaWLedtIng process must wait unkil” ie Acquires bbe yesouree . we. USL: Whe. process can. operate. on the. Tos0Uu%e 3. Ralease; o “The. - process ‘walaases the resource . ‘The OS ‘maka. Aure_ thak tho requested vesourca hos been allocatecl ovr not: =A 4yrbbom table records whether pach verource ts * Pree. or Allocate, and if allowtad to which procs. Fq for ceadlnck toweling some, resoutes: type Consider a, 2ystam with, 3 Eape. deives - The. 3 processes hold ona ope. chivivar - Af cach process “wequeses anokbey papa. olaiva., tha 3 prowssas will ba. in. oleacllock stale. Fxomple. Jor deadlock iovoluag di Mewent weourca kype. Consiolas a Agee with ona. prinker and ona tape dai, Sapposs. P; 13 fololing tha. tape. dive. and Pf 3" folding Eho. printer. 6f Py yaquedts ta. printer ard Pj reyueals the. Hapa diva ,a cleadlock. occurs. Scanned with CamScanner [DEADLOCK CHARACTERIZATION | adr a claoctiock , + —> preceasserA Never finish nd > Systans vesoureas are. tiod ap >prevank other jobs from sharting NECESSARY CONDITIONS ; A deadlock pritcation may arco ¢f oad 4 conditions Rolol Aimalbanaously in a Aystemn . Mutual exclusion: only one, process: at a time! can. use Eho_ qosourer.- 4f another pracass -veqpests bhok wsoume , tha. requesting pvecass rust ba elelayad until tho. *asourca. has bean veleased - 4g Holl and wait: A procags musk hold atlease ona, “resourer_ and woik bo acopu'a. odditional venouréars thak ore. corrrantly folol by othar proteases . A source, can be valeared valunsanily by the process folding i, ator that. process has completed i bask . Scanned with CamScanner a ra aaa ard e

You might also like