0% found this document useful (0 votes)
16 views14 pages

4 Synchronizarion

operaring system notes

Uploaded by

dskumbhar23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views14 pages

4 Synchronizarion

operaring system notes

Uploaded by

dskumbhar23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Late

a Synchronizaion.
Poce ss Syncheniaton is needed when miple
pecesser executt Concurraiy shany Same
teSourtes whìch s t ionsiglent ot data
& to a o i h e inconsise nd stat

PrceuaData pcar|
B

To avoid this type of inconisfency of data


the po(eHes need to be synchonizeal wh eoh

On tbe basis ofsyncheniatio, prrees ate


cateqoized
O Independent p e - Execati on of one
does net affet +he exe cuthion
o her proreges
Cosperatig pro ers i- Exec wtion of One ppces
a ffectS the erecuhon o other

Race condiion
when muliple peses acress 4
maniplate the Same data eoncurren
outcone 6f eyc(ution deperd
ia whih e instruthon executee
To rd agaist the ee oreiion he
hat only àre proce
to ensuk Hat at a
ime Can be y manipdahig he
ical Sechion Boblem
To ayoid the ace (onlihion

secti on code seqment that


Can be accasel by ony ont prees at a
Hne
preses (Po,P, - -fo)
w h a t

Syskm has
e c h a n
tach,po ceas hog seanen of ode called
cSHcd seehon in which pocess ot
changig On
do
vrnable, nniy

mst geot pomùn entry seaha


chicd sechon

termina Yemainder setion


Code a fky
4he e evit sehon while tre)
strutyh of Praceos

A soluhon to cntcol sehon problem mut


saksy the Allouiny hre teyuinent
Mutua Ekclugin -
pocess is eyecwiry in i5
(8cal sec Hon then no other poesy 5
alleneel to cxecute n the c h l sehon
proes is executirg
pres
are
eiiy outade he cinicalgeion,abl
Hhose peceses hat ak not eecuiy in
their emaindy secioro can
can paricipak in
decidin which uill onler he cóiod secho:
(3) Boundl waiim- A boural mu erist
numbey of imes that other
Prces e CAP allowea to eney thei ChHioal
Sechoo

TMethods to cele he hcad se cHon prble m

0 Pe terson's soluion -( tws peiens)


A, classic slw b ayed solan t the
(hica seohon prblem

boslean las [2]


jhdicate whoue trnn
it is o,ento ib indicate if a prrc

Petrsn', saluhoo is esticteal to to o


pro ce& seg thot altrat eectjon betetn
Pheir XmaineYsrinL

P? stYetc
do
Play 7J = true;
bun j);
3while ( trr)
plag,
DOMS l'ags o
Date

do

flag (i3- ue
tun =i;
44

Xmaindey

both he proreayey cahy the


Hhe cn
sectin soluhon.

Bakeny algoithm fo
This al o is useel whn
of procegses cwish fo enkr in Hheir
Secian at
cHical
Same ime. Befo
in its ica
Sec hon Prao eies
toleen no, Poceas havira cmalesA
enthg
ill enter o he
SeeHon.
reeive fame token no
then
hit token ho shoyd be in intesirg
oYder,
ate

do

choosig ril- true;


number li]- mar Cn4mber eJ
number [h-J) +1
chooig CiJ foe

cwthptetchoorirgt)
do begin
while choosig L I o
no-op
while (humherLiJ =o
=*fayt; bosleean
egt) boolean Testardet
C boolean
weahon Cnhcal eKeçuts
bhe &
lc Io he tkeeuckeolit nt is it If
wehg foec becomes
On locteal /s
about inquires pro(e0 a
Sechon
ica ener
i towans Proreo when
eithe Aalke
can which vanable \oclc shareo
hlu by
tesoe also
Secin
qt mhcal In blems po The
so(ution H/
TageN
Semaphoe '
AA
Sermophoe s Variab
v le
accesS on source by
mu tiple pro cessey and avoid cnca by
what
Se cion proble m
S e n a p h
? o x

A Sermaphore is tnter variable


which an be CeerS ad only Hrough tuo
o perahons woit c and signalc

woit OperoHoP

whie (s<
| no operefion
S

Siqna) operehen
Siqna (s)

Stt

waitcS)
crftica
Secho n

signds
Data

Tonp
Advantags of Semap ho
0 allows Only precers into cnical
Secion
() Thee is na 0esource astye becawe
of busy aiirg
Types of Semphoe '

0 Binary Semahax
t is Semophoe wit an
Value
can rage only
only between
It is also knon as mutex locc
Pr(ese Shar Same muk
Hhat is iniH alzal to 1 Hhen preceas hag
to wat un i l he lock be co mes
The poess can make he muten
semophsrt and stortS
Secin when it Comples t
Se cian it can
ciical
thealue o
to o hey
Can
do

waitc muten)

sigad tmtny
wmainler Seha
ge No.
Date

2) (ounfy semapho

Can rame Kr un eytiteel do main


The semopho is iniiaizal ne af oures
a vailable Pach proceys Hot ant o ye
esaure per forms wait) operathion. When
pro (es eeoHe esOure it per forn Sianalc)
operafiaon

Classfc problens of Stnchyenizaion:


markr.
ftar
(OBoureleel Bufer prablem ( rduser b ergumer
problem)
Reale hie prb)e

e Dinirg philasplrer prblem

O Bourleot BtRr preb)em


dlso callal pdueey-conumer
Problem
producey
) Crate an Jem and add to he bu ff
2) Do net overo bufr
Conmer
) Renmone iem Fyom
) Do n t want to_90 ahea i)
poduer
waiig

buffer size f is Gxed, Con Sr wait


new ilem Pooducey waiki buffor
is hell,
Senaphot

Serraphnh.

Pro ducY conmnr pee


do do

?
Wait Cfu;
pro duce an iem. waitlmutn

waitleph);
waitlmut);
C4of Cmu),
add o buffor
S5nd(bp):
Sigrad (muta)
ignd (Rell)
vealcount |neger
SemaphoK 2
muttn
=1
()Wit
data he reod only Reaolers
processe oftpes Jwo
Read waihg
wnter aiiy
ne
reeder3
Teade2)
teadey miPk
betuin
hmc
a
hared iS
that le GYelatal
to is 1t
problem wnk Reader
peas then
onine Cannst proces then
enphy0full
o oeY S
mirg pdueing
d afkr | back valve
consuni mode
o IS
pmdueirg
Process
S
Dale
Dalo

Yeadey wnky
proesy preess

whileCtrue)
tohile(4rue)

wait(muttn)
is
reodiount tt, per or
Sg0 (vs)
rait(A);
slgnal (mutr;ohr rader .
ne YeaeY

Can enty

) reading is perkrmal.
wait (mubn) wutrto
Hadcownt Jear
f (readlout=o)

Signd(muh)

3) Diniy phi lose pher pro b)t m


The proble as follows -
( ) Considev 5 philosophers ther hinkig avd
eahrgSeated
Tet arod cìrcular toble. n te
cente table bow|
singh chopslicks.
4,
Fach philo Sopher ha
ayol ngrt chopsticks t helshex
One chopskcuy ot a hre
Afler eacirg philosopher put b h chopsits
bact down on the table d Sta hinlti
chopsies ay sharirg it is ot pJnbe
or all be eahy t He

pritsgh
Rice
bow philwgh
2

philasoph
4 philap
3
3 2

Sernaphoe chopPsick C5] -iSai zel


fo 1

philoopher
piske
tahl e

twait (chopSh ck Ci3);


wait ( chopshcle (i1? ).5 )
cheps
side
down

pnlophr
eaten pu
star hinleiy.
signchopstt ci)
Signad( chosKae Li ]7 5 )

Hhìnkig.
ewhile li)
DOMS Page No.
Date

proble ms pinigphilosopher pro bley


( Dco dlok

You might also like