Ospp Chap02 Part5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

KaceConotion.

AAace conlton is an un dsisable situatio


that occur s When a
syctem attempte to
Puyo
tuo ormore PeRatoni ab tbe Same time, bu
because oq the nature o the desice Or S/nm, the
Opeuatons ut be done io be propca Seqwna
to be done COxrecty.
To Sum up
mulbple ArocecscA CA Opuatnq On a
Shana data

Einal outcome depends on h e Osdke in


hicb heArocesLes_Aun

Consicu he Proguam belo

#include <stdio.h>
#include <unistd.h>
staticvoid charatatime(char *str){
char *ptr; int c;
setbuf(stdout, NULL);
for (ptr str; (c "*ptr++)
=
l=0;)
putc(c, stdout);
int main(){
pid_t pid;
if((pid fork()) <0)
printf("Fork Error\n");
else if (pid == 0)
charatatime("this is child\n");
else
charatatime("this is parent\n")
return 0;
The Output beu Ccan be: Cone possible).

this i s tbis 1s ChiLo

Parest

We Cao use WtC) to Ovecome the Aace


Conditon Situation bus

ntiproce se LOauaicaGon

process Con be.

Lodep-ndent t cannot aject es be ajected by-


the ohea process executing in the system

Coopesctingi lt_Can aJJect on be ajjected by the


othea proceses execuing in tbe Suster
Any precess that shores dota i t h othca
ProLess s a Copesatinq AroLess

Why a llow paocess CoOpesaton

Lnyomnauon Sharing Sevcaal uscas may be

itereste d n the Same piece aj injoma ton.

ompula Gon Speedup. Spit a process int»


Sub basks, to un astee, each executea.
in paso l e l
the
Ncdula»itq We may ant t build
Systomla.
Oivohng tthe
h e Sys tem
Sys tem unCton
a modalak jathi'on
threads.
OA
into Sepaiate pOcesses

tven an Individual usc ay work


CnveD.eDe
at he Same time.
On man4 tasks

OopeatngProcesces Aaqure_a n ibteaprocess


ttwo
COmmunicaion. CCPC) To acbicve we bove
uo

undamcotalmodels

Shared Mcmory-

Mess.aqePassinog
CShasLd memoxy Can be jastea as mecsaqe
passingis achieued typically usioq System Cals)

process A

shared memory Shaxe d


process BB
lem0
Model

kemel
pULa kaub heqade

process A

process BB
Mescagg
Pccainc
2wde L

message queue
mom,m2 ma mn
kernel

Shared lemery

Typically a Shasud memory regoo Tesides


in the addre ss Spoace og thepRcess CheatnG
the sbaked -memory Segment

Otha procesteR thbat uwish to C o m u o i c a t e


sing this Shared-mtmory Seqmenb musE
atacb it to heir address Space.

Procecsu musE aqAee to PrOCesS anagemot


Pre tocols

EromeleiPuduce LonsumeL a b l e m
C producen proCeseprodules a aom
h a t 1S Consumcd 64 a Consomc process
Code
Acompile Iney produe Csscmbly
Consmed by Csscm6lc As semnblea

Poduces objccE madules consomed by a

Locde
oduca &Consumua nf ca act tbrough shea
Cal it
shaand
ve
Bj/ C
he Sqnchr o n i a ton Oj prooduc ca &
G Consuma
Consumez
happens us a ly oia a implementaton
Crculac g u e u e
Llnbounded Buffc Uo practcal imit on the
Size o the buffe
bounded Bujje Fixed bujje Sihe

Mcss cePassng

Proviodes atleast two piatms:


Sen dLmcss a9e)
ceive Lmessaqe)

Me csagu
Messag Sent Can be fxed leasy to implemcat
C vauable i'n Si 2e .

T O d to Comnuniate, cc communicatoo
n k mut exist between
processes. J6s Can be
achieved by

Direct O indire cE Communicatoo

yn TonoLus O Qslynchrono us CommuDicalion

Pulonatic Cplieit
ujeng
Ppakash beq4
Waming
Lo dxect Commusicaton:
Send CP, mest
age)-
Sceive ( , messaqe)

CpLutu name wbom to Send


O rom ubom to receive u mesSaG2.

A comunication isk ecactl4 one, with


Cacty tu20proceccea ts estabisbed cA he
DcedJo aomliaiCabon.

T lodirect Commuotcation.
Sesd LA message)
seceive CA, cssaqe
Ais a maibo. cr psE

Communicotion isA may be ouodated with


mOre t h a n tuwo pocesics anbs Wil be in

Coraeordenc to mailbox auocated & links


O C tobuisked only i they bave a shansd
mailbox.

SunchonioGon
be
mcsSage pauing Con

-6locking
on-6locking
m e s s a 9 cs

Uon-Blockine

lock'ncq Casyne
Csiyn

Send Receive
Scod Receive

Ea-Bockinq Send Caooot _Serd Dext message


until message is aeceived

A sustem Ca bave OauOus Combioatons O albove.

Buyfeain9
Zuo Copacby Queuelength is O. 7ust bave bloceirg
Send.

Pounded Copauty Gueue has jinite length o


Sendea bloche b e n gueue jfu

Drbounded Copaa ty u e u e leng t is potertal


infinite. Senda nevca bbcks
paakonsb begac
T Cent -Seva
Systems IPC s ually tnplemen
-te dusinq-

-Sochets
Remote ProCadure Cols

Piees
Remoke mehod Isvocaaon

ATE Queston

The following two functions P1 and P2 that share a variable B with an initial value of 2 execute
concurrently.
P2

cE- D=2 B
B=D-

he number of distinct values that B can possibly take after the execution is_

Answe is3 BCan beld 3 dijjcssnt values


Can you jstigy

You might also like