0 ratings0% found this document useful (0 votes) 146 views30 pagesPPL Unit-4 Part-1 PDF Notes
Unit 4 of ppl part 1 (JNTUH)
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
A Pubic dass g entra, Af
Pubic int C, dj zc
Public void dyow C) See
: Public Voi StU) oor}
Jere CER: De on
| the A al 8 losiey, clon ith Le
vtobly, one Sho = :
| : uM in bebe -fiqune: Nobiw thob He
metho vk ‘
| foi Ret pd asi. wuts 44 C'S: ve Vtoble
|
Pointy te tu tool fay A's arta method
tods fo As dyes
da Poy Asovea
Cools for AS ones
ode Y4 Qs dyos
Jqure: An ao be ;
ple obtle ciks with single iwhevitonta:Conuyyent
ve
Dicdebvodachion'- MURA application’: runs
x =i mn Oe lor puln e
Convent in Softwone exetukion Con olLuy ot Pause
dipfperent bevels:
y Bytrukion Lyel ( eneuution “bso ov move cir:
mstyudiod Simultanemusly)
W Statement level (exerting starr ey move” high Lvel
longquege Stolemedy simultaneously)
W Unit Level ( enevating tise ey move Subpreqvany
unify simultaneously)
™) Pyoqvom Lwel [exerting bee or more_Proqtany Simubtoneou
UU pull pyotuscoy Avdbitecbury +
Boge ence
A lange numberof afferent Computer ondnit tury
hove mort thon guage Proley gov ond ton Support Some
Foren of Conusvret eneukion:
| the fist Computers Hick hod multiple pyoussors
| hock ome gererel - Purpose Prosser ond ge oY move.
other proassors, ofter Cotled Peviphero! protysers, thet wereweal only for input ‘ond output opevotions» Thay wo
onchitedure aowesl these tomputsy , which oppeamed
vai thes Late iqsos , ts ewouite ow progyom oki le
Contarverttly Performing impuk ey output Por other
Proqvomsy Bas
By the eonly 1960S, tune were machiny thet
hod multiple comphte proussors. There pyousgors weve
wed by the poo sdredluln of ta opevoting System,
which distvibuked seponct jobs From o butua joo
Gute te the Seponcte PYoLYS0¥S +
Computiny that Love multiple PYoUSSor Lat love.
operete independent but whose operotioy tan be
Syadwoni3ed one called multiple - Gustvuction multiple-dota
[rLM0) Computers: Coch prouygor in on MiMD tomputer *
enetuty ib mon ingtyuction Stream:MIMD Computery Con oPPeor in thw alistinge
Configuration’ distributed ond Shoned . memory
Systems. The distvibuted MLM mohing,, iy
which eaur Pyousser hey ib} oon memory Can be
aither butt in a Single distyibutedls perhopt over
a Lange onea+
pe Cakeqoyies of: Contry:
es
ae
‘There one sw distinek cote goviy OF Conuuyyent unit
| Got-vols The most neatuyol cot egovy of Conwarvenuy 16 that
in void, ressuming thet move than gue PYoces Sor
1s
brwohith, §¢ ovatloble , Stvenal P¥°9Gy¥om unib -Pyow
|
|
|
het
the Some Proqvem literally eneuite Simultaneously,
[arbi 1S physica Contry enuy"
A Slight velonation ob this Coneapt oP Conturventy
alors the PYoqyommen ond the pplication softwere te
ossume thot ture ore muti ple protes cays Provi
dingaint Conuryeruy, ihn in Pout He actual 03)
creation oF Progyony i Feking plate in int érloved
Poshion ona Single prouscoy: This ig Logical onuurventiy
Preqvoms that hove Covmutiny bub ss eee
Sebproqvems, though thy aru somelints talltel
“905i —lonuuvyedt", hove oa Single thyeod ef loutvol.
Proqvoms enotudeal with ply sal conurventy ton hove
multiple thyeass of lorctvel: Earh Protyioy tan enOudi
ome of the threads. Although legitally Conuurved Preqvom
Qneuation may actually have snly a single tread of
Gmivol , Suds proqrany Con be disiqued ond analysed
only ley imagining thin os heving multiple thyeacl; of
tontval + A proqrom dusiqnedl “te hove vere thon one -thyead
of Lortyol 16 Said te be multithreaded»|
® Tabrodasin te Sth program ~ Level Con tury enty~
a4 Funclaba ent Concepts =
A tosk iS a unit of a Proqyom , Similan tte o Subpreg yam,
thet ton bein Contuyyed exetution with other unib
| of the Some proqvem: Eth task ina PYoqvom Can Support
Lone Heyead of lant ol: Tasks one Somertinu, tolleat
| oy Some longroays , foy enomple Tova ond cH, Certain
methods sevye os tosky. Such metho ano enreiutecl in
objec called thread,
three charoctenist 4 of task, abistinguish trem
“om Sobproqrvoms, FivSt atesk may be impliitly Stanteel
[shane 24 asubprozrom must be enpluthy cabled.
Selonal , whan a proqyom unit invokts a tos, in Some
tosey it need not waitfor the tosie te tomplte ib
enetation before Continuing ub mon.
Hind, hts Hu eneustion of o tose 4 lomplteol
lsvtyol naey eo not yéban te the unit Bhet thot
Stanted that enetution:Tests Fatt inke tw gtrevel cotegoris’
heavy werght anol light weight. Simply Stated,
[2 lows weight boat execaty in ib can oddvas spate.
Lightweight tasty oli un inthe some oddvas pace
Syrchionization 4 a mecranigm that lontyol
He order in which tosky enetute’ Tivo kind, of
Synchronization ane yequiyeel when tort, Shoru deta:
Coopevetion oncl Camnpetition -
DCooperotion Sindawvoridation is vequived beboen
task A and tosk @ when tosr A must woit Poy tose R
‘be lomplile some Speuific activity before tose A
Gon begin oy Continue if enemtin .
) Competition Synchyowisction 4 Yequived between burp
“Pesky wher both yequive the we of- Some YU ouvir,
thot Connot be Simultoncovsly Weel.
Speci fitelly iP tose Needy te aultic chan eee
Location y ighile tose Q ag alussing, X, tosk A| ma weit for tosk R te Complete ub Protssing
of %* So for Cooperction Synchyonizotion , tosks muy
Necol te woit fox the lomplabion of Specific. Protssing
on which theiy lovvect operation depend , whereas
For Competetion Synuonigation, Losey may need te
| wort for the lomplition of ony othe Prous sing by ony
tos tavvently oluuving on Speuibic Shoned doba.
A Simple form of Coopeyetion Synebonization fan be
| Uytvoted bya Common preblint Colled the
| Prodtan cbonumer problum: This Pyobln ovigitiated
‘nthe development of operesing Sy aeuns im which
one Prog yom unit Pyoduuy Some dato Volar oy Yedmae
Jona onather uses t+
Produud data ane sully ploud ina Stovoge
bu}fen by the Producing unit ond vemoved Wom thet
buff ev by dhe coms uring unit +the Sequéne of: Story te and Yemovaly gl 2
‘ bebbrer bythe losing: wits the buffer must be
Syndryonided the Comumer unit must ret be allmoed
‘to tobe dota from the buffer iP-tle buffer is empty -
The Wroduan unit tonnot be ollesed te ploe
nwo dota in tre buptey iP te buffer is Pull:
TE clonipy the tompetition pyoblun , tenyidey the
FoUlroing, Sunanio! Sup Pose tosk A hos the stelameit |
Totol 421, white Total 4 a shored wmbeqen
Voriclle . Furthermore , Suppose tosk 8 hoy the
Stotement ToTAL *22+ Task A ond task 8 lould by
te change ToraL ot the sometime
At the moukine lenguege bwel, tous tosK mor
attomplish it, opevation om TOTAL with the Pollasinoy
thyée - Step Prouyss
DPekdh the volue of ToTAL:
2) PevPoym the ontthmebic. ofevotion »
3) put the nuw volue back jn TOTAL» | Seyer A-tosk dies whin &G enerulim
: Tesky Con be in Several different state +
WN SA tosk 1S im the now Stole whin it hoy
been Creotedl but hoy not yo begun ith execution.
[PrBeedy: A veady teak is veady-to Yun bub wat
barvertly Yunning: Either it hey wot been given
PYotssoy time by the stredulin:
3: Running! A Yunnineg task is one thot is urvvently
exetating j thot is, it hoy a Pyolss¥ and Ub ole
is bein eneruted:
ty Blouked! Actosk that § loleckel hos bears Yunning
but thot exertion wos internupted by one of
Several diffrevert everdy , the most common of which
iSon impud oy output operotion.
5 Ptod' A dead tok is no Longer ative fags
is lLompleteal
oy tk 4 emplicitly Killed by the Prog vom:mS
uNat-O-
: _UNS TS
A Plow di oqvom of the state of atesk 15 Shown
im below Figure:
Figure! Flime alicgvom of tosk Stoty
sate
one imPortort issue tosk eneumtion is the
Following | How igo Yeody at tok chosen te move te
the yoning Stote when Hu tok tarrontly Yunning
hos Lebere Lloued oy whose time glia hoy expived 9Tet eromple , Suppase tain A ond stosk g
both vued the Shanedl How KX ond Y
omplate thin work. farther mart) Suppose thet
task A gory podtescion FX and tok gary
Possession of Y- APLtn Some enetiion, tose A need
Tour Y te dowlinue, So it yequests ¥ bub must
walt until @ Heleoseadk. wetther Yveljwquithy the
youn it Poscasy and ay ayaulk, both base hey
Leness , quattenitaina that exbittion of tbe. prover
will even Compleke rool oe oe
loss of bvemass 16 Called! “dead lock”.D Sema d hory
ee
A Somophave i$ a Sinaple mechanigm the. lon. be uyed
rts Provide Syrchyoni zolion of Lostey,
3) Dntyoduction =
a
In an ehhot te Provide lompetition Synchronigzolion
through nukuelly enka sive actys te Shared dota
struiduvy, Semaphory Con obo be wed Provide
Cooperation Syrebwoniael on.
32 Coopeyetion Synchvonia ation ~
copes: Aen buffer used by Produany and
Gwimey! te Waste the dippered oppreoey to
Providing Coopevotion ancl Competition Synckvoni Zetion.
Fey Cooperotion , Suck a buffer mut hove some woos of
yelording both the number of empty pocition and the
ramber of filled position im the byfen( te prevent
bouffen underpler and oven foo)»[eae Semophere ton be.
used fov his punpase: one Semaphore Vonially
toy orample , empty spb — ton uye Ub tamben to
maintain the number of empty Location ia a Shaneol
boffen wed by Produany ond Consumeny , Pull spats - lon
(CU Guten te maintain the numbenef fUeal location
inthe bupfen-the queues of Heese Sekar, fan
| Store the dutniptor of toss -thet ive been Povied ts
fot or aces te Abe toffee gue of “oly
(Con Store, produan’ tosis that are woiring -fry_ evot labs
osition fhe bobren; the quame, of Pull spot’ Con
| Stove, Lorgumen! rtayiey wetting) foy. voles te be plated
ia tbe befor. |
Ouy example buffer 14 dasig re 24 an obttyodt
aaias type in which ol data oxters the buffer through
the Subproqvom “DEPOSIT ) ond alk « dota eaves the
bouften thyough the Subprogyom ‘FETCH’.iH The DeposaT! Subproqvom nsec only steed inistt
the empty spots’ Susephove te See whethen there
ONS ty empty Position. Th theye 4¢ ot Least ome,
Eton froleed with -the “DERSIT', which must hove
the Sde effect of detremendting! the Counten of
‘enly spot) Tp the bofben Ru, iby callen te
DepesET’ must be masle te soait im the ‘empty spit
qpent for an empty spot to belent ayeilable.
When the Deposit’ 5 Lonrplets the DEP" Subpreayom
iMcremeds tle Countey of the Pal spats Semophore
te wdicole thet thene i¢ ore move titled Lecation
im the buffer
The operation on Serophore Tey often ane net
patton sth are clave Shera Dott ayaa!
Sulopyoqvany- Thanefure » the" DEPOSIT’ opevotion just
daybed 16 outuclly cuomplisthed in Pont byColts te \oeit' ond “yelease!:
|The Tasik! Semephore Subbpronram | iy used te
| tut the lounten of a given Semophove Vonioble »
| Fy te Ge ezeaten, sha aot ble Clemens
cone ot BK opeyotion: Tn thy lore the Lounten
[Volue of tha Sumaphare Vanichi is, datnamenrted
te tadicce that thine i noo om fioen of shat
SU County TF the Volue ofp the tounten 4 Zero, the
| collen pst be pleted onthe welting quine of the
fear: Venioble, ond Wal pfs uscer must be given
le gome othen vtody task, .
The “‘Yelease' Semaphore Subprogram ty used by
oO task te ollma Some other tuk te hove one of
whatever te Lornttr of tu spetifieel somophore Vaniokle
Count » Tf tHe queve of the Specified Semophoye Variable
& empty , which Meory no tok 4 aeiting ovelsaie!
‘mMownwd ib texoken,"| The Follesine, ana Condise Péue pseudlacoce Laue
| of woit" and veleose’:
|
wot CaSemophere)
iP aSemaphere's lourten >o then
detrement asemophoye's Counter
bye
fut the Collen in asemephoye's queue.
attempt te tombe dontvel te Some veady tos,
end vf
veleose (asenaphore)
if asenaphore!s queues empty (notoxk iy waiting, then
ncremed oSemapher’s Gruen
abe
Put the calling osk im the -toykveady. queue
trorpn Cortvol tea 403k fromaSemaphorels queue
end
tromplt proqyom thet implements Coopenction
Syrdwroniaction fora shored betes Dn thy cour, the
shaned bofher Storey, ink gen Voluey ond ig a Log ivally
Gyuslen Strucune-Two ¢ UY one Used ‘to rune against
(bho undin Plas of ovenplos, ths Providing
|
| Locpention Syrdryorizotion. Assume ‘thot the buftey
| '
shes Lngth ~ BUFLEN, ond the voukiny thot out ually
hone pubote i olveody est oy ‘regen! ond pepacrT’
|
ACESS te tre Contin of a Semaphore one specified
by dot notoHom: for eromple , WP Pal spots iga Semop hove
ith Counter is referenced by Pullspaty. Count »
Semophore fullpst, empty spat ;
Pull spst. Count Foy
erpty Spsts # Cunt 2 BUFLEN 5
tosk Produan;
beep
ees Produce Volue - —
woit (empty spi); Lweit for a spote,)
DEpoaiT (vALvE);
Tdaose (fullspsty Jj Linewase
exabtheogs
end Produan;
AiUed Spaces}tosk Grswner) ®
Lsvp
wort (Pal spety) Gmoka Sune it is rot empty]
evo valve)
veleose Cenpty spot) 5 $ mouse empty Spous}
Ho benyure VALUE- —
ord Lop
ed LoWuresyy
3:3 Compekition SyrdhvoriaationK
a ee ce eer
| A Semaphore thak yequivy only a binary -volucal counter
bitte ties ones usedli cto Provide: Compe ti HOM syndavo nization
i the folowing enomple, is called a *binony Surophevel
fas
Semophere actyi, Pull epots, empty Spots ;
alts, Counk 2};
Aw Spots + sunk oy
empty Spoty Goank > BUFLEN j
tose Produan;
> Produce yALve — —woit Lempty spots); $ weit Py a Spore}
wait (acess); foot py acese
DEPostT (VALUE) ;
velrose (acuse)
Lvels wauith acu, 3
Yeloose (Full cpt) }
Limcreose Pidleal Spat}
Lovp
wait [Full spe); Smoke Sue ig not empty
| ait Laces); Soot Poy access]
ete (valve);
Yeas (arase); $yebinguish actays?
Yueose Compt cpot, ); $ intreoye empty Spaces?
a> Comune VALUE —-
end Leap
end issuer;| Monitors
_——x ———
el Comapetition Syndrvoni zabion
oe
lhe: prjrommer dou net syndronisa, mutuolly enclasive
aitys te ghened dato through the we of serophory
oy othey mechanism Getomse the aces mechorisn4
font Pork of the monitey, implomentralion of a nonifey
[con be mode tequoranter Syndwonized acess by
oll osina only ort ofty, ob a Hwe:
ee Snel sy nbyoni3oti onim
A preqyom a foun tk) dnd a monitey Lak
PYovidyy Synchronized acess te a Comerryeritly shored
buffer iS Shown in beleo Fiquyes In thiy Sree
[the inbenpole ts Uke moniter i$ Shaon 25 the tise
loony Lobeld “argent! ond *yemave! (Por the insertion
ond ventoval of data):Fiqure: A Preqyom Ushio.
monileY -to Contel acuyss te a Shoned
bof
|
\
)) Messeqe Possing’—
oo oO
|
BN the Contept & devonmwy Mess ose g>
rere Se Se sag
[Mesode Passing Can be’ either Syndbroriow oy osynchyoneu,
| eve, Wwe dasinibe Syncrvonoy Ms Loge Possing The basic
ltt of Synchyonowy mBhoge Possing 16 that| i)
| testy ane often busy, ond vohen busy; they cannot be
_inkecrupted by other unity Suppose tay’ A ond tok R
one in entation, and A wishy to Sind a mugcoge te 8,
cleanly pee Bene buy, itinet duivoble to olla
jorothey tor t inkenmapt it thet would distugt
[ae bayyenk PYoUssi ng.
| A task en be dyigqned So that it Lon Suspend
. vty enewtio¢n ot Come. point ites beloue it reidile
Loy betomse it neec information Prom onothen unit
“before it ton Continue, This 16, Like a Penson whe ig
weiting For on important Coll. In Gomes Losey’, Here
iS mething eke te clo bub git ord aid.
| Hoeven | if tesk Aig worting fox ia mansage,
pote time tose @ Sends theb mecoge , the mycooe Con
[be traated Thy odtial trom mission of te
eS iS led a “yendervouy",8) Ado supe Poy ou aie,
bi frdacnaptaa
os Sytadic foven of Ada testy is Similen ‘te thot
igaiaiene Packagyy.thaye are “tev Pont - © Sputi picabion
Pank ond a o boolty fas - both with Some name.
the iwkerpate of a tort iS ih ontyy poi , ov Leveling
whore it lon acupt mysege yom other tosky-
Beromye thuye entry Poinds one Pant of ib jnkerpae iki
notarol thet {hey be Listed it the specificskion pont
oho tosk: Relose a Yerdeavous ton involve on ercbonge_
of infovenotion , r1sS09+4 ‘Con have panamebiny , thavefore |
teak entry poi! must abso om Ponramelty, which
must alyn be duyinibed’ in the. pet ficokion pank »
As on example of on Ada tosk spetification, lomsidey
the RUooing: dade, whith imdday ia single ey
| Pa named Eakvy-1, which hoy on inmode Panometen:Tork Task Eromple is
obey Eatry.1 (Sten tin Lakeqen);
tnd Tork romp Ley
A tosk body must imubade somre. Syntoutic. foyer of the
enk¥y Poids thet lovvespand “te tha Tonk! Lowey
im that tosk's gpesifidelion fank' In Ada , they task
body entyy Poids one Spee fied boy Cloayes that ore
twkvoduced by the “acupt' voynved, ord:
An ‘oceaps Clea esl; defined asthe vonge of
Stahimed beginning with tu acept' vertved word
ond ending with the motching ‘end’ yeseyved word:
A Simaple accept’ clouye bios the Porm
actpt enkyy nome (Formal paromekiny) As
endl entyy =nowe;
The “accept ankyy nome matduy He name in on
es lous ‘mn the orsoticttra Lose Spetificotion font -The dPtionok Porametory PYovicle ty. on
of
smut Ging dita
lelween the allen anol the.
‘catled teak: the Stotiments betwen the ‘lo’ and
the “end' define the opevolioy tetlot take place
deaving the Yundervowy, tye crote mud ome
LinaeRteg Coed the ‘actept close body"
the Following iSthe ‘creletol bodes sof the tosk
whet gperifitaHow 105 giver Previewsly |
tosk bowly TosK _Exomplr 16
begin
Lsvp
octept Enkyy_1 (Stem in Tikegnr) do
end Enkyy 1 »
tnd Lswp 5
| ond Tork. Enomple }
The ottept douye oP Uy task bovly isthe’
taplomentaki on of He entty nomed Eabyy-1 inthe tose
Speupitebon: éTp the exewtion of Tosrenompl beginy and Yeoh, ©
[ate Enby-1 acupt Uause before ony othen task Surely
a messoge to Enkyy-!, Tork. Eromplr is Suspended .
Tp onothin tosk Sends a musoge te Enbyy-1 while
Tose Enomple \ Gop Suspended of iff axrcept a
ferdeavey oluns ond the acupt! dame body ix
eneabtd thon, beloye of tu Loop, exeustion Protul
bok te te accept TP ro athey tosk hoy Sek a
message te Exkvy-1, exeuttion 1S agoin Suspended +
weit Poy Hw nenk mae Shane:
oe cojerain Spihrdgatiqn?:
Eorh soccept' claye Con havea guard okteched ,
Watt fom of 0 shar ase j tha tan! delay
ond eavors «Foy, enomple
When vst full (Buffer) =>
actept Deposit (new—Volue) J,
odinal dese with a twhin? clawe is
either oped or Uaceds Tp the Rovluan expression
cob the “ahen! louse 4 uvvertly tue, thet
tacupt! douse is taled open ef the Qoolean
“expression is aie cee Uause ig Colbed “base
ibs Genpetition Syrhyonizetion
Lag Pallosing, 45 an tromple. afron Ade tosk thal
implores a monitor foy o buffer
EX toxk But -Tosk 6
entvy Deposit (Stem: Tateqen) ;
envy Fakuh (Stem: ouk Dakeger) ;
end Buf Tos y
tos body Buf Task 46
Buf Si30! Comrstant Integen +
| 100)
Buf annoy (1; Buf size) of Drtegen 5
Filled 1 Dnkegen, Yonge. 0. Bufsize rao,
Hew _In
Neuk_ out: Drkegen Yonge 1,. Qupsider=lybegin
Lsof
Sulek
When filled < bufsize =>
actept peposit (Gem : tn Bakoen ) do
Buf nent an) te Tten)y
end Deposit j
Nene dn ss (Wek mod Buf sige Jar)
Filed v2 filled +4;
or
Wher AUel po =>
actept Febdr (Stem: puk Integer) de
Them +2 Buf (Nek out) 5
enol folly
Henk guk! = (nents ouk mod Bufsize) 415
Pulley Filled —14
eral Sale;
end Lsopj
eral Bop = Task;Ta thy example , both ocupt ‘actept’ Clawyy
aneentindesl: Thuy entercleal clouiey Can be.
eneuated Conturvvently with the tosty thot tolled
the ossotiotd ‘otupt! Clouse,
(the testy fav a'pyoduten! and a‘ toyumen!
‘{hot Could vse Buf Teak’ heve the folooi ng Porat |
ie
Ex tex produun;
| toske Comwmen;
tosk body Producten ig
Neo. Value ! Dakegen j
begin
lev)
- — Producten Nts value —-
Buf Tork. Deposit Neo- Volue);
| end Lop j
end PYodeeuny
| test body forsurren i
Stored value | ‘Duk ego;
aa
| Buf. Tose» Fekrh Liered. volue
end. Continued Leo? -~ eas Stoved volue ”