concurrent programming concepts, per brinch hansen

24
Cncurrent Programming Cncepts PR RH Informaio Sciece Cahforia lsue of Tecoogy Pasadea, Caiforia   This paper descrbes he evoluon of language feaures for mulprogrammng from even queues and semaphores o crca regons and monors I sggess ha he choce of language conceps should be guded by wo smple prncples: Frs, shoud be possbe o undersand a concurren program n me ndependen ers by an eor proporona o s sze; secondly, should be possble o sae assumpons abou nvaran reaonshps among pogram coponens and have these assump0ns checked auomacay The cenral probems of muprogramng are usraed by annoaed algorhms wren n a wel-srucured programmng anguage Key words ad prases: srucured mulprogrammng, programn languages, operang sysems, programmng errors, resource proecon, compleme checkng, correcness proofs, sequenal and oncurren processes, snchronng evens, semaphores, shared daa, muua excluson, crcal egons, monors. CR categories 4.22, 4.31, 4.32, 5 Somewere ere re decons made a are no ron n an ene a are ubjec o nog ore hn he eron b of e decon mker Logc meod a be, re rrnge e wa n wch eron b lS o  be roduced o a ro be O coure, "a be rer moran Preen ue meod una nroduce erona bas n uc a w h mke robe mobe o oe correc Our uroe u be o re aern he b o no onger erferes n h deruce w w e oce of degn n no onger nb cr of for HSOPHR LXANR Noes o e Syes  o Fom RODCO his papr dsribs a attitd toward mtiprogrammigth programmig th is sd to otro orrt atitis by omptrs.* It tris to idtify abstrat proprtis of programmig agags that faiitat th dsig of arg, riab mti In aer, e erm muipogammig ued conen o denoe rogrmg echue ued o conro concurren rocee on ge roceor a we uroceor em programmig systms. h this sd to impmt ths agag opts, whih appy both to sigprossor ad mti prossor systms, ar dsribd swhr. 1 Wh a w programmig thi, sh as mtiprogrammig, is itd program mrs wi itiay s it i a ompty rstritd mar to disor ts pottia At a atr stag wh xpri with its pratia imitatios has b gaid, d sigrs bgi to rogiz th bts of a mor rstriti agag otatio whih aris thir ow drstadig of pro grams ad abs ompirs to dtt sri os rrors his sry dsribs th otio of a gag fatrs for mtiprogrammig drig th past dad. iw this dopmt maiy as a grada shift from opts that ha a strog rsmba to assmby a gag fatrs toward a otatio that orags hirarhia strtrig of pro grams. Sra sf proposas ar ot mtiod hr, ad thos that ar idd u vy Db

Upload: xorxpto

Post on 06-Apr-2018

235 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 1/23

Cncurrent Programming Cncepts

PR RH

Informaio Sciece Cahforia ls�ue of Tecoogy Pasadea, Caiforia  

This paper descrbes he evoluon of language feaures for mulprogrammngfrom even queues and semaphores o crca regons and monors I sggessha he choce of language conceps should be guded by wo smple prncples:Frs, shoud be possbe o undersand a concurren program n mendependen ers by an eor proporona o s sze; secondly, should bepossble o sae assumpons abou nvaran reaonshps among pogramcoponens and have these assump0ns checked auomacay The cenralprobems of muprogramng are usraed by annoaed algorhms wrenn a wel-srucured programmng anguage

Key words ad prases: srucured mulprogrammng, programn languages,operang sysems, programmng errors, resource proecon, complemecheckng, correcness proofs, sequenal and oncurren processes, snchronngevens, semaphores, shared daa, muua excluson, crcal egons, monors.

CR categories 4.22, 4.31, 4.32, 5

Somewere ere re decons made a areno ron n an ene a are ubjec onog ore hn he eron b of e

decon mker Logc meod a be, rerrnge e wa n wch eron b lS o  be roduced o a robe O coure, "a be rer moran Preen uemeod una nroduce erona bas nuc a w h mke robe mobeo oe correc Our uroe u be o reaern he b o no onger erferesn h deruce w w e oce ofdegn n no onger nb cr of forHSOPHR LXANR Noes o e Syes

 o Fom

RODCO

his papr dsribs a attitd towardmtiprogrammigth programmig this sd to otro orrt atitisby omptrs.* It tris to idtify abstratproprtis of programmig agags thatfaiitat th dsig of arg, riab mti

•In aer, e erm muipogammig uedconen o denoe rogrmg echue

ued o conro concurren rocee on geroceor a we uroceor em

programmig systms. h this sdto impmt ths agag opts, whih

appy both to sigprossor ad mtiprossor systms, ar dsribd swhr.1

Wh a w programmig thi, shas mtiprogrammig, is itd programmrs wi itiay s it i a ompty rstritd mar to disor ts pottiaAt a atr stag wh xpri with itspratia imitatios has b gaid, dsigrs bgi to rogiz th bts of a

mor rstriti agag otatio whiharis thir ow drstadig of programs ad abs ompirs to dtt srios rrors

his sry dsribs th otio of agag fatrs for mtiprogrammig drigth past dad. iw this dopmtmaiy as a grada shift from opts thatha a strog rsmba to assmby agag fatrs toward a otatio that

orags hirarhia strtrig of programs. Sra sf proposas ar otmtiod hr, ad thos that ar idd

u vy Db

Page 2: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 2/23

224 Pr rnh Hnsn

COTET

I noduion 222 Sequenal Poesses 224 Unese onuey 2264 Suued oueny 22 DJO Poeses 26 Tme-Deenden Eos 27 Tmn Snals 2 al Rewns 26 onwnal a Rewns 24

onluswn 244Aknoledemens 244

B1oapy 244

Cph © Assc f CmpuMche c Geel pemss epubsh  bu f p ll p f hs mel sed pvded h ACM's cph ce S

ve d h efeece s mde hs publc s de ssue d he fc h ep pvees ee ed b pemss fhe Assc f Cmpu Mche

omug Surveys Vol 5, No , Deember 7

ar y ma t istrat a gra atid tward h sbjc

h cra prbms f mtiprgrammg ar isratd by agrithms writti a high agag I ha icdd i

frma assris i th agthms ad id argmts f thir crrctss t shwhat mtiprgrammg ccpts ca b dd as ccisy as stia prgrammg ccps I may ways, this sryca b rgardd as a xpadd rsi fa arir papr 2. W wi bgi with abrif charactrizai f stia prgrams

SQAL PROCSSS

thgh mst prgrammrs ha a iti ti drsadig f what a squniprocss is, i may b sf t istrat thisccp by a xamp grihm 1 dsa stia prcss hat ipts a xdmbr f rcrds R R, . Rn frm stia , pdas ths rcrds,

ad tps thm ahr sia h agag tati is brrwd frmPasca [3] h s ar dcard as wariabs, rdr ad prinr ach csisig f a squnc f rcrds f sm typ Tdc ard swhr) rcrd f yp T cab appdd r rmd frm a scby mas f tw sadard prcdrs, puad g. h crr rcrd is pt i a ariab, h f yp T. h ariab   csh mbr f rcrds prcssd it ca assm itgr as frm 0 t n.

Agorih Sia pdatig

v rdr, prinr sequence of his: T i: n

ben i : 2 whe   < n do(3) g his rdr) 4) upd hs)

5 pu hs prnr) 6) i : 7) end8 end

h prgram ds a stia prcssi trms f d rprstd by cstats

Page 3: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 3/23

Concurent Proramn Concepts 225

and variables) and operations on data (represented by statements). During the execution of the program, the operations are car ried out stctly one at a time, and eachoperation is completed within a nite time.

The result of an operation can be dened byassertions about the relationships of databefore and after its executionIn Algorithm 1, we can make the followingassertOns about the stae of he vaablesbefore and after the executOn of the inputstatement in line 3:

comment i out of n records processed(where 0 : < n) ;get (this, reader) ;

comment 4 i out of n records processed(where 0 � i < n) an this = inputrecord Ri 1

Sequential programs have two vital prop erties:

1) The eect of a sequental progam isindependent of its speed of execution. Allthat maters is that operations are carriedout one at a time wih postive sped andthat certain relationships hold before and

afer their execution The timeindependentbehavior of seuential programs enables theser o ignore details over whCh he has nocontrol (such as the scheduling policy of theoperaing sysem and he precise timg ofoperations carried ot by processors and pe ripherals)

2 A sequential pogram delivers the sameresult each tie 1t is executed wth a givenet of input dat. The reproducible behavior

of seuenial programs under any circumstances is partcularly important for program valdation It nables one to isoateand correct program errors by systemaictesting

These properties of seuential programsare so well known that we end o take themfor graned Bt as we shall see, these prop ertes can only be mainained for multiprogrammg sysems by a careful selectOn of

language concptsAlgorithm 1 a wellstuctured proga

that can be analyzed in a stepwse manneras a set of nested operaions. At the mostdealed level, the program can be descbedin ems of assertions about each satement

The followg assertions will hold beforethe execution of lines 18, respectively.

comment 0 out of n records processed(where 0 �n;

comment 2 i out of n records processed

(where 0 i n);comment i out of n records processed

(where 0�i < );comment 4 i out of n records processed

(where 0 �i < n) and this = putrecord Ri 1 ;

commnt 5   1 out of n records processed(where 0 �i < n) and ths = updatedrecord Ri 1

comment 6  i +1 out of n records poc

essed (where 0� < n);comment   1 out of n records processed(where 0 < i �n);

comment 8 n out of n records processed(where 0 �n);

nce the dvidual statements are understood, one can dene the eec of a seuenceof saements by a sigle pair of assertnsAs an example the body of the whie satement in Algothm 1 can be dened as a

single operaion by means of the followgassertions comment i out of n records processed

(where 0 :i < n)process next record and increet i byone

comment i out of n records processed(where 0 < i �n);

The next step of simplcation is to reduce the wh1le staement to a single operation

comment 2 i out of n records processed(where O�i�n);process the reaning ni records

comment 8 n out of n records processed(where 0 � n);

Finally, he whole program can be denedas a singe operaion

comment 0 out of n records processed(where 0�n);process n records

comment 8 n out of n records processed(where 0�n);

At his point, only what he program does asa whole is relevant bu the details of howt is done are irrelevant The possibility ofreplag comlex descriptions by partial

Comptg Sun·ys VL 5, N 4 December 1973

Page 4: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 4/23

22 Pr Brinh Hnsn

tn functonl pct of t cn b dcrbdn n mor conomcl trm. Th th

whole purpose of structured programming!

I-

 I I I II

I II

_I

L _

_ _

Flowchat of lgonhm

dcrpton, clld bstrtins ntlto nbl u to undrnd lrg progrm.

Fgur 1 owchrt of lgorthm 1. thow tht th progrm cont of ntdttmnt, ch wth ngl trtng pontnd ngl complton pont lgorthm 1cn b nlyzd by octng n rtonwth ch ttmnt, nd grdully rplcng th rton by fwr nd fwr rton. t mot mportnt tht rgrmwith hirrhil strutur n b builtn unrst in til by n intlltul  rt rrtinl t its siz nd tht cr

m Suys 5, N , mb 7

t lo ntl to u hrrchcltructurng of progrm tht control concur

rnt proc, nd choo lngug contruct for multprogrmmng tht cn bundrtood n tmndpndnt btrctrm othrw, w hll nd ourlunbl to pply ymtc mthod of progrm nly nd rcton.

UNRESTRICTED CONCURRENCY

roc r clld nurrnt f thr xcuton orlp n tm Mor prcly, twoproc r concurrnt f th rst oprton of on proc trt bfor th lstopron of th othr proc nd Thprogrmmng tchnu ud to controlconcurrnt proc r clld multirgrmming.

ssumtins will b m but th

s t whih nurrnt rsss r ut (xcpt tht b pot . W wllbnt rom h w mpton n twowy 1 t wll ncourg u to try toundrtnd mulprogrmmng ytm ntmndpndnt trm nd 2 t wll prmt h undrlyng mplmntton to u dynmc chdulng lgorthm to chcnt rourc hrng.

n of th rlt d of multprogrm

mng w to pcfy th trt nd complton of proc by two opron whch wll cll strt nd mlt (n th ltrur, thy r oftn clld rk nd inTh mnng of th oprton cn bt bllutrtd by n xmpl

va tsk rsnsben

sa tsk do 1 ;2 ;compee tsk3 ;

end

ntlly, th progrm wll b xcutd ngl, untl proc. Th mnt

Page 5: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 5/23

Conrrent Pro rn ne 22

s tsk do S

wi start the execution of statement S asa new process. As soon as the new processstarts to run the od process continues toexecute the next statement S2 When statement S has been executed the new processindicates its competion by means of a ariab tsk of type response Foowing thisthe new process ceases to exist After theexecution of statement S2  the od processwaits unti the response ariabe indicatesthat statement S has terminated The program then continues to execute statement S3as a singe seuentia process (We wi notbe concerned with how the process and response concepts can be impemented.) Figure 2 shows a owchart of this program.

Agorithm 2 is a concurrent ersion of thee updating program (Agorithm 1) thatuses the strt and oplete statements Thepurpose of introducing concurrent processesis to permit input/output operations to proceed simutaneousy wth updating opera

IG 2  owcha of pogam o usae sa ad com' opeaios.

tions Agorithm is deiberatey written inan unstructured manner that maes it dicut to understand A westructured agorithm wi be presented ater recommendthat the reader not spen too much time trying to understand Agorithm 2 at this point)

lgorith Concurrent e updating (unstructured ersion)

v reer printer eece reing printing response netthis lt i 2 . n

begn 1 e

get lst reer n 2  e

pte lst

s prining o pt lstprinterget this reeri 2 ;we i < n d

s reing do get netreer

pte thiscompee prntnglt this

s printing do pt lstpntercompee reingthis neti i 1 ;

edcompee prntinglst this

edpte lst

pt lst prnterendend

The program inputs and updates the rstrecord R It then starts the output of therst record and inputs the second recordR2 at the same time. The program now repeats the execution of a cyce that in genea, inputs the net record Ri 1 updatesthis record Ri and outputs the lst record

Ri simutaneousy. When a records haebeen input (i n the program competesthe output of the second ast record Rn.Finay it updates and outputs the astrecord Rn

mu Suy V N. mb 9

Page 6: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 6/23

Page 7: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 7/23

nurrent Prrammn nts 22

rerd Ri and ast updated rerdRi 1

comme 6 i ut f rerd pressedwhere 2 i < n) net input rerdRi 1 and this updated rerd Ri

comme i 2 ut f n rerds pr essed where 2 < i n) net inputrerd Ri and this updated rerdRi 1

A omariso of assertios 4 a  7 sowstat assrtio 4 is a relatio tat remaisnariant after ea exeutio of te looWe te loo termiates assertio 4 stilols a is eual to n

comme n 2 ut f rerds pr essed where 2n) net input re rd Rn and this updated rerdRn 1

Te rogram ow oututs te seo lastreor Rn 1

comme   1 ut f n rerds pressed where 2 ) and this inputrerd Rn

Te eet of te iermost if statemetmet a be summarize as follows

comme 0 ut f n rerds pressedwhere 1 n) and this input rerdR1press n 1 rerds

comme n 1 ut f n rerds pressed where 1 n) and this inputrerd R

If n 1 te assertios 2 a 10 are eui alet, a if n 2  te assertios  9 a10 are euialet Tis oers te two asesi wi te if statemet is eiter skieor exeute

Fially, te last reor Rn is uate aoutut

comme n u f n rerds pressedwhre 1n) ;

Te wole rogram a be uerstoo asa sige oeratio ee as foows

comme 0 ut f rerds pressedwhere 0 n) press n rerds

comme n ut f n rerds pessed

where 0 ) ;Tis ourret rogram as reisely te

same aateisis as a wellsutue se uetial rogram It a be aalyze i

NU UDE UU

I. owch o h body o th wl stt m oihm 2 

tems of timeieeet assertios by aeort roortioa to its size, a assertiosabout sime statemets a grauay berelae by assertios about struturestaemets uti te wole rogram as bee

reue to a sigle statemet ee by twoassertios. Tis abstrat esritio of terogram ee eabes te rogrammer to ig oe te ourret ature of te solutioTo see tis, it is suiet to obsere atte iitial a al assertios 0 a 12  forAlgoritm  3 are ietia to te assertiosmae at te begiig a e of te se uetial ersio (Algoritm 1

I te reious isussio, te ourretstatemet as ee a use iformalyto gie you a ituitie uerstaig of itsmeaig We wil ow exliitly isuss teassumios tat le to te simiity ofAlgoritm  3

omu Suy V N m

Page 8: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 8/23

23 Per Brinch Hansen

F 4 owchat of the bod of he w sttemet lgohm  3.

5 DSJONT PROCESSES

Thr is on striing irnc btwn Algorithms 2  an  3 When concurrent statement are used, te program text drectlyshows where a gven process beg and ends. This simplication is achi by rstricting th from of schuling. Thstart an complete statmnts nabl thprogrammr to initiat an trminat procsss in any orr h plass A concurrntstatmnt ns procsss that ar startan complt at the same tme Compltgnrality of programming implis compltabsnc of structur As a compromis onhas to loo for programming tools that arintllctually managabl an at th samtim practical for most but not ncssarilyall) applications Th concurrnt statmntis on such compromis.

Snce a concurrent statement hs a nglestartng pont and a sngle completon pot,  t s well-suted to structured prograng

Figur 4 shows a owchart of th boy ofth whle statmnt in Algorithm  3. In contrast to Fig  3 th prsnt owchart can bcompos into nst oprations This xplains why w wr abl to ruc assrtionsabout simpl statmnts to assrtions about

m Sey 5, N mb 73

structur statmnts an thn ruc assrtions about structur statmnts to assrtions about th whol algorithm.

t may sm surprising that th us ofconcurrnt statmnts in Algorithm  3 in no

way complicat th formulation of assrtions Th informal argumnts ma in aor of its corrctnss ar quit similar to thargumnts on Algorithm 1 in Sction 2 tturns out that w wr abl to apply squntial mthos of program analysis to aconcurrnt program simply bcaus theprocesses dened b te concurrent statements are copletely ndependent of oneanother Ths procsss oprat on isjoint

sts of ariablsprocessgupatput

varablesnxt rarthislast printr

Thy ar call dsjont or nonnteractngprocesses Th input upat an outputprocsss ar carr out simultanouslyonly to utiliz th computr mor cintly.

ut concptually ths procsss coul justas wll b carri out strictly squntiallyas n by Algoithm 1.

inc th procsss in Algorithm  3 hano ariabls in common thy can b analyz on at a tim as unrlat squntialprocsss Consir for xampl th concurrnt statmnt insi th loop. It can banalyz as thr inpnnt oprationsn by th following assrtions

cn 5a 2 out of n recors processed (whee 2 �   < n);get (next, rader);

cn 6a next = nput record R  1(where 2  �   < n);

cn 5b � 2 out of n records processed (where 2 �   < n) and ts= nput record Rupdate (ts) ;

cn 6b ths = updated record R 

(were 2 �   < n)

cn 5c 2 out of n recrds processed (were 2 �   < n) and las

updated record R 1 put (last prnter);

Page 9: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 9/23

Cnurren Prramm nceps 1

ommen c u f n recrs prcesse where < n;

Hr assrions   and 6 hav bn sli ohr airs of assrions on for ach rocsssamn Each air of assrions dns

our assumions abou a variabl   ha r mains cnsan during h xcuion of hconcurrn samn and our assumionsabou h variabls ha ar prvae o hcorrsonding rocss and may b changdby i

Sc h rocsss ar disjoin h con juncion of assrions 6a 6b and 6c holdsafr h xcuion of h concurrn sa mn

In gnral w can dn h roris ofa concurrn samn by h followingrule f sjnness Th samn

obegn 8 8 ; . 8n oend

dns samns 8 S2 , 8n ha canb xcud concurrnly as disjoin roc sss he jnness mpls ha a vara ble v change by a saemen 8 cann bereference by anher saemen 8j whr i) In ohr words a variabl subjco chang by a rocss mus b sricly riva o ha rocss bu disjoin rocssscan rfr o common variabls no changdby any of hm

Th gnral rul ha w inuiivly followd in analyzing Algorihm  3 can bsad as follows Suos ha w nowh following abou samns 8 , 8 8n ha ora on dsjon variabls

Samn 8 will rmina wih a rsul R if a rcondiion P holds bforis xcuion

Samn 8 will rmin wih a r suls R if a rcondion holds bforis xcuion

Samn 8 wil rmina wih a r sul Rn if a rcondiion Pn holds bforis xcuion

Thn w can conclud ha a concurrnxcuion of 8 8, . . 8n will rminawih h rsul R & R & Rn if hrcondiion P & P & & Pn holds b�for is xcuion I should b addd hah assrions P and R mad abou sa

mn mus only rfr o variabs haar accssibl o 8 according o h rul ofdisjoinnss)

TME-DEPENDENT ERRORS

An rror a squnal ogram can b locad by raing h xcuion of h rogram svral ims wih h daa ha rvald h rror n ach of hs xrimns h valus of slcd variabls arrcordd o drmin whhr or no a givnrogram comonn wors This rocss ofliminaOn coninus unl h rror has

bn locadWhn a givn rogram comonn hasbn found o bhav corrcy in on sw can ignor ha comonn in subsqunss bcaus i wi coninu o bhav inxacl h sam mannr ach im h ro gram is xcud wih h givn daa Inohr words ur ably es a large se quenal prgram n a sepwse manner epens funamenally n he reprucble

behavr f he prgramA carful rogrammr who wris a wl srucurd concurrn rogram such as Agorihm  3 and ouins an informal roofof is corrcnss can sil ma misaswhn h ys h nal rogram. And hmay no nd all hs rrors during a roofrading of h rogram x n ossiblmisa would b o y h concurrnsamn wih h oo of Agorihm  3 asfollows

oegnge nex reaer upae hs pu hs prner

oendIn his cas h concurrn samn will

inu h nx rcord R corrcly buwill uda and ouu h currn rcordR simulanously So h ouu rcord willnormally b only arialy udad In amulirocssor sysm wih a common sora rcord occuying say 6 machin wordsmay b ouu wih x words udad and6x words unchangd whr 0 x 256 Th rocssing of a sing rcord canhrfor roduc 7 dirn rsuls If

Coutg Survey o 5, No , Deeber 97

Page 10: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 10/23

Page 11: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 11/23

Cocurren Proramn Conce 233

oammi, bt I o xt it to b aot too o t i o ma, i at mtioammi tm ioa ab b o o I aom atO abot it ia mtioammi tm o x am, oati tm a ati ti a

T o ioit i ito to t oamm it ab im to tatxiit tat tai o o bit o o aot a to o atomat ttio o ioatio o tiamtio To mak mtioammitta maaab a aoabit, ioit o o b ob Bt, a a , amtioammi m mt oaio a mt ot o to xaata a ma T omot o a ot tatmt mt, oxam, b ab to iiat ti tmia tio i a ommo aomo iab ;oti, it o b mob to tm a ot tatmt i tmi

at a a o T coegn coend otatO i ti ommiatio obm omt , bt it a to b o at omot o oammi t a bt o at b a omi . T o oi tio ib aa at to oto itatO amo o

MG SGALS

ot o tat a ommoaiab a a teractng o commu catng rocesses W o cometeo t o a o, ommoaab a a to k tak o tqt o i ocooeate o ommo tak, ommo aia b a a to ab o to ako ot to a ot btak a ot

o ti W i t tm i i oo roduces a sends a q oata itm to aot o tat receea consumes tm It a obio o tait tat t data tems cannot e re

ceed aster than they are sent o atiti qimt t i omtim ato a t xtio o t io ti t i o oaot ata itm. Synchronzaton i a a tm o timi otait o ti timo o itatO bt oto

T imt om o itatio i a xa o tmng sgnals bt to o ko xam i t onterruts to a t omtio oaoo ia oatio to ata oo ot ki o timiia, a eents a i amtiommi tm to oiot o W a o i to wt o a t, t xtio oit xt oatO i a ti aoto causes t t. t oiat a tm o o a aiti oo a o t

T ooi oam tat ttamiio o timi ia om oo to aot b ma o a aab e

o t eent Bot o a am tob ia:

e eentcoegin

cyce sender" cause e ente ;

encyce receer"

awat eente ; end

coend

atioi o ti t xt i a atm tm i o o ot tak a b tmiia to ot o tat a ott tak.

I tio  6 o tat imta o oatio o t am aiab a ato a a mb o t t I

tat otxt, t obm a a b aoam o No a t am ob m aa: T ot oatio, awta cae bot a t am aab eBt a o o a t a a ioa tio o t o iJoit i o i

Coutg Suvey, ol 5 No 4, Deeer 97

Page 12: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 12/23

234 Per Brnc Hnsen

tention s that he processes should exchangedata. o we u relx e rule of dsJonness nd er concurren rocesse o ccess sred les y e of welldened syncronzn oerons. ur next

tas is to determine under which condtionssynchronizing operaions are welldened"To analyze he eect of an eraction

etween the receiver and the sender in theprevious program, we must consider all thepossile ways in which the execuion ofw and cue operations can e inter leaved and overlapped in ime In a coninu ous me scale here are inniely manypossiilies o consder A drastc simplica

ion clearly needed o reduce this nityto a nite small) numer of cases The onlypracical solution is to assume hat syncronzn oerons on en rle cnno  e execued e se e. In otherwords, w and cue operations on a giveneven vaiale can e arrarily terleaved(u not overlapped) in ime If a processtries o operate on an event varale whileanother process is operaing on it, the sysemmus delay he former process untl he a ter process has compleed is operaion onthe event variale

If hs reuirement is satised, there areonly wo cases to consider in he previousprogram: eer an  w operaion is executed  efore a cuse operaOn or fer i. Ifthe receiver waits efore he sender causesthe nex event, an ineraction ewen the

two processes is dened y he followingseuence of operaionsomment receer no wnw een e ;omment receer wncuse een e ;omment receer no wnBu, if the sender causes the event efore

he receiver wais for it, the receiver will re main delayed unl he next even is caused

omment receer no wncuse e en e ;omment receer no wnw een e ;ommnt receer wnThe most important result of his analysis

Coutg Surveys, o 5 o 4, ecebr 973 

is the genera oservaion that uul excluson of ll oern on sred rleenles e rorer o nlyze e oss le eecs of roces ercon n ne,sequenl ers For the special case of

event variales, we have also discoveredthat the ne eect of w and cuse pera Ons depends on the order in which theseoperatOns are carried out r, to put t moresrongly een oerons force e rorer o e wre of e rele seedsof e endn nd recen rocesses.

The programmer does not conrol theorder in which concurren statemens areexecuted; he is therefore unale o predic

he eect of a process teracn volvingevents. In a realme sysem, he program mer has essenially los conrol of processschedulinghe canno dene a process hatwill schedule oher processes in a predicalemanner. Even variales are only meang ful to use when one can assume ha aprocess never s ased to carry ou anohertas until i has compleed is previous as.Although this assumpion may e saised

in some applicaions, it will sill complicateprogramming tremendously if one dependson i The programme mus hen e awareof he relative speeds of processes under allcircumsances If a muliprogramming sys tem is so large hat no single person under stands is dynamic ehavOr in detail, theindividual programmer cannot mae relialeestimaes of he relative speeds of processesunder all circumstances. In particular, it will

e an intolerale urden o verify hat hespeed assumpions are uninuenced ymodicaions or extensions of a large sys tem.

We mus herefore conclude hat evenvariales of the previous ype are impracical for sysem desgn Te eec of n ner con eween wo roceses us e nde enden of e seed wc crreou

A far more attractive synchronizg ool,he seore was invened y Distra in  965 [4 5] A semaphore is a variale usedo exchange iming signals among concurrenprocesses y means of wo operaions wand snl (originally called P and All

Page 13: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 13/23

Concrren Prorammn Cnces 2  35 

opeaios o a semaphoe exue oeaohe i ime. Assoiae ih a sema phoe v ae o ieges eig he umbe of sigas sent a received hough va a queue i hih eeivig poesses

a aai he seig of fuhe imigsigas by ohe poesses. Iiiay heumbe of sigas se a eeive ae zeoa he queue is empy.

Sigas ao be eeive fase hahey ae se. This semahore invariant

0 received sent

is saise by usig he fooig syhoizaio ues

If a wait opeaio o a semaphoe vis exeue a a ime he received < senthe recved is iease by oe a heeevig poess oues ; bu if received sent he eeive is eaye i he queueassoiae ih v

2) A signal opeaio o a semaphoe vieases sent by oe if oe o moe poesses ae aiig i he queue assoiaeih v oe of hese poesses s eabe ooiue is exeuio a received is iease by oe

We assume ha a poesses aiig oeeive sigas eveuay i be abe ooiue hei exeuio povie a suie umbe of sigas ae se by ohepoesses) The sheuig agoihm usefo a semaphoe queue mus o eay aypoess ieiey i favo of moe ugepoesses. Bu apa fom his equieme

of air scheduling o assumpOs ae maeabou he spei oe i hih aiigpoesses ae aoe o oiue. The eakassumpio of nite rogress ahe haabsoue spee) fo ay poess is a eue heme of pogammg We have maehis assumpio fo sequeia a isoipoesses, a o e make i agai foieaig poesses o ahieve simpiiyof pogam aaysis a exibiiy of impe

meaio.Agoihm 4 ees a asmissio of

mig sigas fom oe poess o aoheby meas of a semaphoe v

lgorithm 4 Exhage of imig sigasby meas of a semaphoe

v v semahorecben

cycle sender sigl v) ..

end

cycle receiver wait v) . .end

cend

Sie wait a sgnal opeaios o hesemaphoe v exe eah ohe ime asiga a be se eihe eore o ater heeeive eies o a fo i. I he sase e a make he fooig asseios

abo he sequee i hh a ieaioakes paecmment receiver nt waitg and 0 received sentsgnal v) cmment receiver nt waiting and 0 rceived < sentwait v) cmment recever not waiting and 0 <received sent

I he seo ase, he wait opeaiomay o may o eay he eeve (epig o hehe received sent o receed< sent Bu i ay ase he subseesignal opeaio i esue ha he eeveoiues is exeuio

cmment receiver not waiting and 0 received sentwait v)

cmment receiver waiting and 0 re

ceived

set r reee not watingand 0 < received sentsgnal v) ;

cmment receiver t waiting and 0 <received sent

The ee of a ieaio is iepe e of he oe i hih he wat a signalopeaios ae aie ou. The commutativeroerty o semahore oeratio nalesthe rogrammer to ignore the recse moment at which a timing signal is roducedThis is eaiy he mos impoa oibuio of semaphoes o pogam aiy

he uses of semaphoes i be esbeae he e have aie he fuamea oe of muua exusio i muipo gammig

Coputg Survey o 5 No , Deeber 9

Page 14: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 14/23

236 Per Brnh Hasen

8 CRTCA RGONS

We w now onsde onuen poessesa exange daa o abay ype andno us mg sgnas) As an exampe we

oose a mupogammng sysem wob sass ae oeed by a poess Pand pned by anoe poess Q Wen ause ob as been ompeed n s sysem,poess P neases an nege v by one Aegua neas poess Q ps e aueo v and eses o eo To dsoe epobems o daa sang we w begn wa nae souon:

v v ntegerbegin

v: 0 ;cobegn

cycle P. . . v : v +1; ..

endcycle "Q

. rnt v) ; v := 0; . end

coend

end

Ts pogam Oaes e ue o dsonness se poesses P and Q bo ee oand ange e same aabe v. Aougs Oaon suggess a weakness o epesen appoa o e pobem we w gnoe o e me beng

Te sae o e sysem aumuang obsass an be dened by wo nege

ay eua o eo) x e numbe o obs exeuedr e numbe o obs epoed

Te aabe v soud epesen e numbeo JObs exeued bu no ye epoed as, e eaonsp v = x - r soud eman nvarant ae ea seuene o opeaOnson e saed aabe v

Te exampe usaes wo genea a aess o mupogammng sysems:

1) The correctness crteron or concurrent oeratos on a shared varale s de ned y an varat eaonsp amus be ue ae naaOn o e a abe and onnue o od beoe and aesubseuen opeaons on e aabe

2) The nvarant roerty o a shared

Cotg Suvy, o 5 No 4. Dh 7

varale s dened n terms o actual andmlct varales. An actual aabe suas v) s deaed e pogam and epesened by a soe oaon dung s exeuon An  lct aabe su as x o

ees o a popey o e sysem a s noepesened e ompue dung pogamexeuon

Te saemens exeued by poesses Pand Q an be abay oeapped andeeaed n me We w, owee onyanaye e ees o an abay neeang o e onuen saemens aopeae on e saed aabe v Te nease o v by poess P an ou ee

  eore ater o n e mddle o e pnng and eseng o v by poess Q So weae ee ases o onsde

v= v +v VO

vv=Ov=v +

vV= V +V: ,

Te oeness eon o e possbeneaons beween poesses P and Q sdened by an naan v = x r) a

eaes an aua aabe v o wo mpaabes x and r To anaye e esus oe ee possbe ases, we mus exend epogam w mp saemens eengo x and r een oug ese saemensw nee be exeued) onepuay x S

neased by one wen v s neased, and rs neased by e aue o v wen e aes pned Assumng a e desed naan ods beoe an neaon akes

pae, we an make e oowng asseOnsabou e s ase:

comment x r vv: v + [x:= x +1comment x r vrnt v) ; [r r + v]comment x r 0;v: 0comment x- r = v

Te mp saemens ae enosed nsuae bakes o dsngus em omaua saemens n s ase, e naan s ods ae e poess neaon

n e seond ase, e aan s asomananed by e neaon

Page 15: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 15/23

ourren Proramm oneps 237

comment x r = v prin (v r r +vcomment x r = 0v = 0 comment x r = v

v v + [x= x +comment x r = v But i te ti ce, te vit" o

oe o te te oce itectio:comment x r = vprin ( v) [ r = r +v]comment x r = 0v = v [x= x + ]comment x r = v = 0

comment x r v Wete o ot te ivit i mi tie ee o te oei of te co cuet ttemet i time i i, ofcoue, uccetbe to te omme wo o coto ove te ceui of co cuet ocee.

Notice tt i te t two ce, i wicte ivit cotiue to be tie, tetwo ocee ve excluive cce to te

vible v wie te e oeti o it:

+ Q prn 0

Q pr 0 +

e coict i te ti ce i cue bmixi te equece of oetio of oceQ o vible v wit oetio o oce

P o te me vbe:

Q pn

+

Q =  0;

Poce Q eom equece o oe tio o te e vibe v It i umett te ivt o befoe teti equece o oetio. But wie teoetio e cie out te vible vm be i viou itemeite tte iwic te vit ot tie I otecocuet ttemet e cie out o te

me vible i oe of it intemetette, te eult will nom be icoectI te evu exmle, oce P tt tooete o vible v t time we x r 0 (ite o x r v ti e to

l tte i wic x r v + (teof x r = v ) .I Sectio  7 we fou tt te eect of

coizi oetio o evet vibe emoe c be eicte ol ifte excue oe ote i tme e eet exme ow tt oe mut lo bebe to ceve mutul excluO of bi t cocuet ttemet eei to e vible o bit te.

Cocuet ttemet tt efe to teme e vible e clle alregions e eviou om coti twocitc eio:

v= v

prin(vv 0

Citicl eio eei to te me vi be excue oe ote time e c,oweve, be bti iteleve i timeWe mke tee umtio bout citicle tt oete o te me evibe:

Muual exlusion At mot, oe ocet time c be iie citic eioTerinaion A oce will lw com ete citicl eO wit te time.Fair sheduling A oce c lwete citicl eO witi ite time.Dekke ow tt mutul excuio

o bit ttemet c be imlemeteb me of load sore oetio oovie tt lo toe oetio o ive vible exclue oe ote itime) . H olutio i f too comicte ieciet to be o cticl vlue 4but t oe ilutte te ubtlet o te mu tu excluio oblem

e iequc of te lotoe oc to mutul excluio iie DiJk t Scote to ivet emoe.Aoitm 5 ee imlemettio ofct eio b me of emoemuex.

Coug urveys ol 5, No Deeber 973

Page 16: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 16/23

23 Pe Bnh Hanen

Aloihm 5 Criica reions imemenedby means of a semahore

v v: inee mue emaphoe ( begn

v 0 co begn

cycle P" . ai mue) v = v + ;

nal mue endcycl 

mue) prin v v : = 0 inl mue

endcoend

end

The decaraion of a semahore mueas been exended wih an ineer consandenin he iniial nmber of avaiabe si nas:

v mue emaphoe iniial)

A semahore is now caracerized by hreeineer comonens:

iniial he nmber of sinas iniiayavaiabeen nb o sina opaon

comeedeeived he nmber of wai oeraions

comeedTe emaphoe invarian ms herefore berevsed sihy:

0 eeived en inial

or e semahores sed in Secion  7, iniialis zero In Aorihm   , iniial is eqa oone

To make a seqence of saemens S, S2, Sn a criica reion, we encose i by aair of ai and inal oeraions on asemahore mue iniiaized o one:

v ue: emaphoe )

. ai mue) S ; S2 ; . . . S inal mue .

Te iniia sina aows recisey one rocess o ener is criica reion nce a roc ess has consmed he avaiabe sina andenered is criica reion, no oher rocesscan ener a criica reion associaed wihhe same semahore ni he former roc

Cog Surveys, 5, N 4 December 97

ess eaves is criica reion and rodcesanoher sina

A more rioros roof of he ma excsion deends on he foowin observaions:

Indeenden of how ai and inaloeraions are sed hey mainain he emaphoe invaan

0 eeed en

2 When a smore is sed o achievema excsion, a rocess aways execesa ai oeraion foowed by a inal oeraionA any iven ime, some rocesses mayhave execed a ai oeraion, b no ye

he corresondin inal oeraion So hesrcre of he roram shows ha he invarian:

0 en eeived

s aso mainained 3 inay, i is cear ha he nmber of

rocesses ha are inide heir criica re ions a any iven ime are hose rocessesha have comeed a ai oeraion bno ye he foowin inal oeraion, hais:

inide = eeived en

By combinin ese hree invarians, wend a he rs assmion abo criicareions is saised

0 inide

A mos, one rocess a a ime can be insidea criica reion

Assmin ha rocesses are schededfairy when hey are inside heir criica reions, we can aso concde h he sae mens execed wihin he criica reions ofAorim   wi erminae wiin a nieime And if he schedin of rocesseswaiin for imin snas in he semahoreqee is aso fair, hen a rocess can ony bedeayed a nie nmber of imes wieoher rocesses ener criica reions aheadof i so a rocess wi aways be abe evenay o ener is criica ren Te im emenaion of criica reions in Aorihm   is erefore correc Noice a heanaysis of his oncrren roram is saedin erms of he imici variabes, eeiveden and iide.

Page 17: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 17/23

Page 18: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 18/23

240 Pe Bh Hnen

a he ha a hare variabe i ueoy iie ia regio a a geeraeoe ha impeme muua euio orrey. I i perey reaoaby o ue emaphor m he ueryig impemeaio

o hi aguage eaure, bu a higher eveo programmg he epii ue o emaphore o ahieve muua euio i ebaabe miar oaio or riia regio wa eveope iepeey byHoare [6]

gorihm 6 how he ue o a hareieger v a wo riia regio o ovehe prevou probe See ao gorihm5) .

lgoithm riia regio repreeeby a ruure oaio

var v shared integeegi

v : = 0 coeg

cycle P rego v do v = v + 1 ed

ed

cycle Q rego v do pnt v v = 0ed

edcoed

ed

I ha bee our pere goa o ook ormuiprogrammig eaure ha a be ueroo i imeiepee erm Siehe preie orerig o riia reg i

ime i ukow, a imeiepee aerio o her e ee a oy be a aerio abou a propy o he aoiaehare variabe ha remai oaihor, a invnt I ha mu be rue aeriiiaiaio o he varabe a beore aaer eah ia regio operaig i

reaiohip I ha reai rue a aime mu i ome way ree he eirehioy o he proee reerrig o he

hare variabe So we ha he ivaa or gorih 5 a 6 i eprei erm o he oa umber o job eeue a repore hroughou he eieeo he muiprogrammig yem. However,ie he rage o uh ipii variabe i

Coputg urys Vol 5, No 4 br

uboue, hey ao be repreee i aompuer wih a ie wor egh heoher ha, aua variabe beig bou oa ie rage a oy repree he moree pa o a yem' hiory We mu

hereore a uio f o he mpii vaabe x a r wih a ie rageha a be repreee by a aua variabe v. I gorihm 5 a 6 he uio i

f = = v

For a emaphore, he ivaa i a reaiohip amog he impii vaabe repreeig a ga ent a eeivedhroughou he ieie o a maphor

0 eeived ent iti

I a ompuer, hee ipii variabe abe repreee by a ige ieger eua oent +iti eeived ha mu remaioegaive.

Peope wih a rog iere i orree proo may we i hepu o eare impi vaabe a impii aeme reerrig o hem epiy i he

progra e Impi uaie have oee o he eeuio o a program; heirsole u is to facilae proga veiaio by makig aumpio abou heye' hiory epii

Ipii variabe a aeme hoube ubje o he oowig reriio

) erio abou a program may reero aua a we a ipii variabe

2) preO ivovig aua a im

pii variabe may oray be evauae" a aige" o ipii variabe 3) preio evauae a aige o

aua variabe a oy reer o auavariabe

riia regio reerrig o ierehare variabe a be eue iuaeouy The ue o neted it egiona, however, ea o a dedlo uepreauio are ake oier, or eam

pe he oowig program wih wo harevariabe v a w o ype T a T'

var v : shared T; w : shared T;coeg

P" rego v do regio w do eded

Page 19: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 19/23

Conurren Prormn Conep 24

"Q region w do region v do .. endnd

coend

Pce c ee e v he me

me h pce Q ee e wWhe pce e ee e w wl be eye becue Q eye e w pce Q l beeye y ee e v becu ey e e v.

The eck ccu becue he pcee ee he cc eO p pe e cee u hchech pce w eey he

cmpe e wh he hepce c be pe h eckc ccu If ll pcee ee eee he me hechc e[ ] cmpe mh pee uch e lck mply by check h ee ccle ee he be he e e whch hee ble e ece he pm

mu p ccl e

h mpleme e, we mu p pe he eece mple cce ce wait sgnal) The mpeme ·ait signal pe u, eqe he ue arbiterhe mpemeO ll mplecc e h uee ecluecce emphe by e pce mupce yem Th ue ee cc cue eel mche e u we ech he mceel whch uce e e kw be cee muuy ecue

The m ccu hs ec mube h it is impossible to mae useful assertions about the eect of oncurrent stateents unless operatios on shared variablesexclude one another in time. Mutual exclu sion ecey euce u y pbe meepee eul m umbe pbe The ue variant relationships mpe he p m y uhe. Teh, hee me ebe u uy ccue p m meepee erms by e pp he umbe cce ue he e u ue

ccue pcee be ubly eecue he ec clyequely nly disoint processes canproceed truly smultaneously

9. ODOAL RAL REGOS

We w w ce mulpmmyem whch pcee c ulce c e e by hepcee. The clc emple he eche messages bewee w pceeby me buer nite capacity ee by lhm Hee he ee

mu be be whle he bue ull he ecee mu ble w whle hebue empy

The mee bue v ecle he ec c w cmpe equece s mee me ype ee full e he umbe mee cuely e he equece.

y, he bue epy full .ce he bue h e capacity he

peO ue sed receve me e mu m he llw buer invarnt:

� full � capacity

lgorithm Mee bue

var v sared records : seuence of full nteger

end

m n: Tcommen send essage mregion v wen full < cpacity do

put m s full full 1

end

comment receive message nregion v wen full > 0 do

gt n s

full full-

end

T ce h he e meem be ppe ul full < capacity e ue he condtional crtcal region ppe by e 6

Cpug uvy N Dem 1973

Page 20: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 20/23

242  Pe Bh Hnsen

regon v when fll < piy do end

Whe the see etes ths otoaltal ego, the Boolea expesso fll< p s ealuate If the expesso s

tue, the see ompletes the exeuto ofthe tal ego y puttg a message m

of type T to the seuee s a easgfll y oe But f the expesso s false, thesede leaves the tal eg tempoa ly a etes a aoymous ueue assoated wth the shae vaale v. The seewll e allowed to eete ad omplete thetal ego as soo as the eeve hasemove a message fom the ue thus

makg fll < py .Aothe odtOal tal ego s useto postpoe the eevg of a message utlfll If fll 0 the eeve eaves thetal ego tempoaly a jos theaymus ueue I that ase, the taleg wll e otue whe the see hasput aothe message to the ue admade fll At ths pot, the eevewll take a message n of type T fom the

seuees

ad deeasefll

y oeI geeal, a otoal tal ego

regon v when B do ; 82; ; en

s use to delay the ompleto of a talego utl a shaed vaale v satses aa spe ot B  ( addto to a vaat I

Whe a poess etes a odtoal tal ego, a Boolea expessO B  s evalu ated If B  s tue, the ta ego IS om plete y exeutg the statemets 2

S' '

. . . n othewse, the poess leaves tstal ego tempoaly a etes aueue assoaed wth the shaed vaale v

All poesses watg fo oe odto oaothe o th vaale v ete the sameueue Whe a poess ompletes a talegO o v the syhog odtos ofthe watg poesses ae eevaluated Ifoe of these odtos s satsed the o espodg poess s allowed to eete adomplete ts tal ego

The sheulg of watg poesses must?e fa the followg sese If a poess watg fo a oto B  that s epeatedly made tue y oe o moe podues"

omu urve, o 5 No 4, Deembe 1973 

ad false y oe o moe osumes " theompleto of the gve tal ego aoly e elaye a te ume of tmes yothe ta egos

We wl use otoal ta egos to

solve the followg polem 8] A steamof ata elemets of type T poue y apoess PO passes though a seuee ofpoesses P P2 . . Pn that opeate othe ata elemets that ode:

PO P P Pn

Eah pa of poesses Pi a Piwhee � i � ) s oeted y a seues i that a hol oe o moe ata elemets

of type T. Th seuees s . . s nae kept a ommo stoe wth a tepiy. Algothm 8 gves a ovevew ofths pipeline system

The ommo stoe s delaed as a vaae v of typ pelne to e dee late)A poess i eeves a message i of type Tfom ts pedeesso a seds a upatemessage to ts suesso y meas of twopoeues

eeive i v i send i v i

Algothm  9 dees the ata type pipele ad the poedues s ad eve. Appele s a shae eod osstg offou ompoets: a aay of seuees s ·

a aay of teges deg the ume offll loatos (messages) eah seuee·a aay of teges deg the mmu�ume of stoe loatos eseved pema

etly fo tasmsso of messages thougheah seuee ; ad a tege deg theue of stoe loatos that ae geeallyvlble fo tasmsso of messagesthough all seuees (whe they have usedup the eseved loatos

Italy, al seuees ae empty ad theppele has ee vded to eseve ageeally avalale stoage A seuee sia always hold at least eseved i mes

sagesWhe ths amout has ee used, theseuee must ompete wth othe seueesfo use of the est of the avaale stoe Sothe odto fo sedg a message thoughseuee s s

fll i < eeived i or vilble

Page 21: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 21/23

ue Pgng ep 3

Algoih 8 Pieie sysemvar v: pipeline O, , n: Tbegn

iiialize ( v) ;obegn

yle POpodue (O) ;sed( O, v )

end

yle Pi"eeive ( i v i) updae ( i) send i v i

end

yle Pneeive (, v, ) onsue (n)

endoend

end

Algoh Pieie sysem ()

type pipene = shared reord

s : array . ofsequene of Tfull eseved

array 1 n of inegeavaiable iege

endproedure send( T var v pipele :

1 n ;regon v

when full (t < eseved () or avalable O do

pu( s (i) ) ;full(i) := full(i) f fu eseved ( i) then

avalable = available end

endproedure eeive (var : T; var : pipe

lie n) ;regon v

when full () > 0 do

ge ( s (i) ) ;f full ( > esee( i) then

available: = available endfull i) = ful ) - 1

end

The i f eeiig messgehugh sequee s ( is

fulli) >

A sequee s (i my temiy i

me h esevedi) messges. Bu he umbe f messges se i sequees eee he iy f theieie S the sysem must miti thefig vaian:

fulli fo 0 � �

vlable L a (full ( eseved (i) )

= apaiy

be sh fmy th Agihm  9miis hs ii, bu he f iseius s hig e's ifmuesig f he ieie

I Hes ii iti egisesses y be eye he begiig f ii egi. ie emust be be e syhiig iis yhee ith i egs s

sh i [2The ii ii egi is im esii f muigmmig sysems I emis be see hethei s is i gmmig t Themi iuy f hieig ee imemei is he eeui f syhiig iOs eh time itiegi is mee

I sme ses, he eeuO be

eue (bt sem eimite by the use semhes T his, e mus ss ie semhe ih eh syhiigiti Whe ess mes i i ue, he ess mus he hehehe esses e iig f th i ti, , if s, ue sig tht iebe e ( y e!) f hem iue As I he ie u esehee, 7the eey f this sheme is bught theeese f iese gm meiy

Cue semes ii egis seem esuite t he esg fsm muigmmig sysems eie use is (bu emembe hhey h t yet bee imemete use i ie) Ahugh these es

Copug Survys N Dcem 973

Page 22: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 22/23

244 Pe Bnch Hnen

siml n wllsucu, hy o nosm o u o h sgn o lgmulogmming sysms such s oing sysms) Th min olm is hh us o cic gions sc hough

ou ogm mks cul o kck o how sh ibl is us yconcun ocsss I hs ho cnly n suggs h on shoul combin sh ib n h ossibloions on i in singl, syncic consuc cll ir [1, 10, 11 I is,how, oo ly o scul ou whhis och my l o

1 0. CONCLSON

I h i o show h h sign o libl muliogmming sysms shoul gui by wo siml incils h ully li o sunil ogmming

I shoul b ossibl o unsn ogm in iminnn ms y no ooionl o is siz

2) I shou b ossib o s ssumions ou inin lionshis mongogm comonns, n h hmchck uomiclly

I h lso iscuss som scic lngug us o mulogmmng Tooi misunsning, I sk you o g hs no s ni oosls bumly s illusions o common hmB lngug concs o muliogmming wll unouly b oos yohs Bu I woul xc ny lisicoosl o

) isinguish cy bwn isoinn incing ocsss

2 ssoci sh xlicily wihoions n on hm

 3) nsu muul xclusion o hs oons n m n

4 inclu synchonizing imis hmi il o coml ogmm con

ol o ocss schuling

KWG

I am indebed to my studens Ram Rao, DavdSmh, and Sanaran Svas for many helpful

Cmpug Survey, o 5 No 4, Deceme 97

commens on ths paper I am also grateful for the

consructve ctcsm of Coen Bron Peer Denng

Bran Wchmann Mke Woodger and the referees

BBliOGAPHY . RINCH ANSEN, P Operat�ng system pni

ples. Prenice-Hall Englewood Cs NewJersey (July 7).

An troduction to operatg systems covergsequential and concurrent processes, processorand store management, schedung algorithmsand resource proectOn. Descbes the RC4 mlprogramming sysem in detai. ntroduces a programmg language notaOnfor moors based on he cass concept ofSIMULA 67

2  INCH ANSEN P. "Sructured multiprogrammg Comm ACM 15, 7 (July 72574578

A condensed presentatOn of the Vewpoinsdescbed he present paper t suggess theuse of event queues h ctal regns asa means of reducg the oerhead of processscheduling.

WT N "he programmg anguage Pas-ca Aca In/maca 1, 7)

A hghly readable den of a sequenalprogramming language that combes the algothmic noation of ALOL wih far more

general data sructures4 DIJKSTRA E W "Cooperaing sequential proc

esses Pogamm Lauages . Genuys(Ed.) Academc Press New York, New Yor68

he cassica monograph that roduced concurrent staemens semaphores and ccalregns It aso contas Deer's solutOn othe muual exclusOn probem.

5 BERMANN A N Synchrozan of commucatg processes Comm ACM 15 (March 72) 776

An axomac den of he semaphoreoperaons, wa�t and s�gnal

6 HoARE C. A R "owards a heory of paralelprogrammg peg Syse Th iqes C A. R Hoare and R H Perrott(Eds), Academc Press New Yor, New Yor7

he origa proposa or condonal criicalregns whch cludes an axmat denof dsjot proces and ctica regns.

7 RINC ANSEN P "A comparison of two synchrozg conceps. Ata nfomata , 72)

A comparson of the use o semaphores andcondtonal cical regns o sove a schedulg problem

8 DKR E W. "InormaOn streams shaga e bue. Jnfomatn Poess Lettes, 72) 7

A soutn o he "p1pele probem by meansof condtOnal crica regns

Page 23: Concurrent Programming Concepts, PER BRINCH HANSEN

8/3/2019 Concurrent Programming Concepts, PER BRINCH HANSEN

http://slidepdf.com/reader/full/concurrent-programming-concepts-per-brinch-hansen 23/23

onen Pon ones 2 45 

9 DrJKSTRA E W h uu o mulpogrammg ym. mm AM , 5(May 968 34346

b dpo o aral uu o H mulprogammg ym.

0 DrKSRA E W. Haha ordg o

ual po. Ata frmata 2 (97) 538

mo v movao o ba

dg do mad THE mulprogammg ym (S alo 9) Rommd u o moor (alld ar or uu opag ym dg

oAR C R ruurd pagg ym.mut ual 6, 3 (ugu 973) 2024

Ilura h u o moo oppd () o dg o a dmadpagg ym