structured multi-programming, per brinch hansen

Upload: xorxpto

Post on 06-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Structured Multi-programmIng, Per Brinch Hansen

    1/5

    This paper presens a proposa or srucured repre

    senaion o muiprogramming in a high eve anguage.

    The noaion used expiciy associaes a daa srucure

    shared by concurren processes wih operaions dened on

    i This caries he meaning o programs and permis a

    arge cass o ime-dependen errors o be caugh acompie ime. A combinaion o criica regions and evenvariabes enabes he programmer o conro scheduing o

    resources among compeing processes o any degree

    desired. These conceps are sucieny sae o use no

    ony wihin opeaing sysems bu aso wihin userprograms

    Key Words and Phrases: srucured muiprogramming programming anguages operaing sysemsconcurren processes shared daa muua excusion

    criica regions process communicaion synchronizingevens.

    CR Caegories: 4.2 43

    opyrght 192, Aaton for omputng Machnry ncGnral prmon to rpublh but not for pro all or partof th matral grantd provdd that rfnc mad to th

    publcaton to t dat of u and to th fact that rprntngpvlg wr grantd by prmon of th Aocaton for omputng Machnry

    Author' addr alforna nttut of chnology nformaton Scnc Dpartmnt aadna A 91.

    4

    Structured M ulti-

    programmIngP Bh H

    Cl I Thlgy

    Inroducion

    The failure of oerating systems to rovide reliablelongterm service can often be exlained by excessiveemhasis on functional caabilities at the exense of

    ecient resource utilization and by inadequate methods of rogram construction

    n this aer examine the latter cause of failureand roose a language notation for structured multirogramming The basic idea is to associate data sharedby concurrent rocesses exlcitly with oerations dened on them This claries the meaning of rogramsand ermits a large class of timedeendent errors to becaught at comile time

    The notation is resented as an extension t the seuential rograming language PACAL [ t will beused in a forthcoming textbook t exlain oerating ystem rinciles concisely by algorithms 2 imilar ideasave been exlored indeendently by Hoare Te conditional critical regions roosed in [3 are a secial caseof the ones introduced ere

    2 Dsjon Processes

    Our startng ont s te conurrent statement

    coben S S2 . S coend

    introduced by Dijkstra [ This notation indicates thatstatements Sl S2 n can be executed concurrently when al of them are termnated te followingstatement in the rogram (not shown here is executed

    Ths restricted form of concurrency simlies teunderstanding and verication of rograms considerably comared to unstructuredfork andjon rimitives5

    Algorithm illustrates te use of te concurrent

    ommuncatonofthAM

    July 92Voum 5Numb

  • 8/3/2019 Structured Multi-programmIng, Per Brinch Hansen

    2/5

    statement to coy ecods fom one sequenta e toanothe

    The vaabes hee ae two sequenta es nd g,wth ecods of tye T; two bues and t, hodng oneecod each and a Booean eoJ ndcatng whethe onot the end of the nut e has been eached

    Algorithm Coyng of a sequenta evar! g le of T , T eo Booleanben

    npu , eowhle not eo!doben = S

    coben

    ou pug pu/ , eo

    coend

    endend

    nut and outut of snge ecods ae handed bytwo standad ocedues. The agothm nuts a ecodoes t fm one bue t anothe oututs t and atthe same tme nuts the next ecod. The coyng outut and nut ae eeated unt the nut e s emty.

    Now suose the ogamme by mstake exessesthe eetton as foows

    whle no eo!docoben

    = Soupug npu/ , eo

    coend

    The cyng outut and nut of a ecod can now beexecuted concuenty To smfy the agument we wony consde cases n whch these ocesses ae abtay intrleavedbut not overlappdn tme The eoneous

    concuent statement can then be executed n sx deent was wth thee ossbe esuts (1) f coyng scmeted befoe nut and outut ae ntated thecorrect ecod w be outut (2 f ouut s cometedbefoe cong s nated the reious ecod w beoutut agan and (3) f nut s cometed befoe coyng s ntated and ths n tun comleted befoe oututs ntated the next ecod w be outut nstead

    Ths s just fo a snge ecod of the outut e fwe coy a e of10,000ecods the ogam can gve ofthe ode of310,00 deent esuts!

    The actua sequence of oeatons n tme w deend on the esence of othe (uneated comutatons

    and the (ossby tmedeendent schedung ocy ofthe nstaaton. t s theefoe vey unkey that the ogamme w eve obseve the same esut twce Theony hoe of ocatng the eo s to study the ogamtext. Ths can be vey fustatng (f nt mossbewhen t conssts of thousands of nes and one has nocues about whee to ook.

    Mutogammng s an ode of magntude moehaadous than sequenta ogammng uness we ensue that the esuts of ou comutatons ae reproduc-

    ible in spite of erors. n he evou eame ths caneasy be checked at come tme

    n the coect veson of Agothm the outut andnut ocesses oeate on dsjont sets of vaabes (g t)and (J eo. They ae caed disjoint o noninteracting

    processes.n the eoneous veson of the agothm the oc

    esses ae not dsjont the outut ocess efes to avaabe t changed by the coyng ocess; and the atteefes to a vabe s changed by the nut ocess.

    Ths can be detected at come te f the foowngue s adoted a concuent statement denes dsjontocesses S S2, . . S whch can be executed concuenty. Ths means that a vaabe vi changed by statement S cannot be efeenced by anothe statement S(whee j ; i). n othe wods we nsst that a vaabesubject to change by a ocess must be stctyprivate tothat ocess but dsjont ocesses an efe to haredvaabes not changed by any of them

    Thoughout ths ae tacty asume that sequenta statements and assetons made about them ony efe to vaabes whch ae accessible to the statementsaccodng to the ues of dsjontness and mutua excuson. The atte ue w be dened n ecton 3.

    Voatons of these ues must be detected at cometme and event executon. To enabe a cme tocheck the dsjontness of ocesses the anguage musthave the foowng oety t must be ossbe by sme nsecton of a statement o dstngush between tsconstant and vaabe aametes. w not dscuss thenuence of ths euement on anguage desgn beyondmentonng that t makes unestcted use ofpointers andSideeects unaccetabe.

    The ue of dsjontness s due to Hoae [3]. t makesthe aximatic property of a concuent statement S vey

    sme f each comonent statement S temnates wtha esut Riovded a edcae Pihods befoe ts executon then the combned eect of S s the foowng

    whee

    P & 2 & & Pn & 2 & & As Hoae uts t "Each S makes ts contbuton tothe common goa

    ommunctonof

    th AM

    July 2Voum 5

    Numb

  • 8/3/2019 Structured Multi-programmIng, Per Brinch Hansen

    3/5

    3 Muual Excusion

    The usefulness of disjoint processes has its limits. Wewill now consider inracing prcsss-concurrentprocesses which access shared variables.

    A shard arial of type T is declared as follows:

    var : shar TConcurrent processes can only refer to and change a

    shared variable inside a structured statement called a

    criical rginegion d SThis notation associates a statement S with a sharedvariable

    Critical regions referring to the same variable excludeeach other in time. They can be arbitrarily interleaved intime The idea of progressing towards a nal result (as ina concurrent statement) is therefore meaningless. All onecan expect is that each critical region leaves certain relationships among the componens of a shared variable vunchanged. These relationships can be dened by anassertion about which must be true after initialization

    of and before and after each subsequent critical regionassociated with uch an assertion is called an inarian

    When a process enters a critical region to execute astatement S a predicate P holds for the variables accessible to the 'rocess outside the critical region and aninvariant I holds for the shared variable accessible inside the critical region. After the completion of S aresult R holds for the former variables and invariant has been maintained o a critical region has the following axiomatic property

    up"region

    do P&I S

    &

    4 Pocess Comunicaion

    Mutual exclusion of operations on shared variablesmakes it possible to make meaningful statements aboutthe eect of concurrent computations But when processes cooperate on a common task they must also be ableto wait until certain conditions have been satised byother processes.

    For this purpose I introduce a synchronizing primi

    tive awai, which delays a process until the componentsofa shared variable satisfy a condition :

    region dobegin ... await B; ... end

    The await primitive must be textuall enclosed by acritical region. If critical regions are nested the synchronizing condition is associated with the innermostenclosing region

    76

    The await primitive can be used to dene cndiinalcriical rgins of the type proposed in [3]

    "Consumeregion doegin await S end

    Producregon do S2;

    The implementation of crtical regions and awaitprimitives is illustrated in Figure When a processsuch as the consumer above wishes to enter a criticalregion it enters a main quu Q associated with a shared

    variable . After entering its critical region the consumer inspects the shared variable to determie whether

    g Sheduing of ondiion t egion men ooe que Q nd Q

    it satises a condition In that case the consumercompletes its critical region by executing a statement Sl ;otherwise the process leaves its critical region mprarily and joins an n quu Q associated with theshared variable

    All processes waiting for one condition or anotheron variable enter the same event queue When anotherprocess (here called the producer) changes by a statement S2 inside a critical region it is possible hat one ormore of the conditions expected by processes in the

    event queue will be satised. o after completion of acritical region all processes in the event queue Q aretransferred to the main queue Q to enable them to reenter their critical regions and inspect the shared variable again.

    It is possible that a cnsumr will be transferred invain between Q and Q several times before its condition B holds. But this can only occur as frequently as

    prducrs change the shared variable This controlledamount o busy waiing is the price we pay for theconceptual simplicity achieved by using arbitrary Boolean expressions as synchronizing conditions

    The desired inarian for the shared variable must

    be satised before an awai primitive is executed. Whenthe waiting cycle terminates he assrin & holds

    As an example consider te following resource allocation problem two kinds of concurrent processescalled readers and writers share a single resource. Thereaders can use the resource simultaneously but thewriters must have exclusive access to it. When a writeris ready to use the resource it should be enabled to doso as soon as possible

    This problem is solved by Algorithm 2 Here vari-

    ommunonofthe M

    Ju 72oume 15Nume

  • 8/3/2019 Structured Multi-programmIng, Per Brinch Hansen

    4/5

    ble s recod cosstg of two teger compoetsdeg the umber of rdr curretl usg the resource d the umber ofwrtr curretl wtg for orusg the resource Both rdr d wrr re tled to ero

    goihm Resource shrg b reders d wrters

    vr srd rcord readers, wriers: ineger ndw sr Boolean;

    Reader

    rgion dobgin

    wit wriers = 0readers = readers + 1

    nd

    read;rgion do

    readers := readers - 1

    Wrier

    rgion dobgin

    writers = wriers 1wit readers 0

    ndrgion w do wrie;gion dowriers := writers 1

    Mutul excluso of reders d wrters s cheedb lettg reders wt utl the umber of wrters sero d ce ers Mutul excluso of ddulwrters s esured b the crtcl rego o the Boole w

    he prort rule s obeed b cresg the umberof wrters b oe s soo s oe of them wshes to usethe resource. hs wll del subseuet reder reuestsutl ll pedg wrter reuests re stsed.

    A correctess proof of Algorthm 2 s outled 7]. ths pper so pot out the superort of codtol crtcl regos oer mr [4]. Compred tothe orgl souto to the problem [6] Algorthm 2demostrtes the coceptul dtge of structuredotto.

    he coceptul smplct o crtcl regos scheed b gorg detls of schedulg the progrmmer s uwre of the seuece whch wtg processes eter crtcl regos d ccess shred resources.

    hs ssumpto s justed for processes whch re solol td tht smulteous reuests for thesme resources rrel occur

    But most computer stlltos rour rely udb lrge group of users ths stuto opertg sstem must be ble to otrol t dulg o rour xpltly mog competg processes.

    o do ths progrmmer must be ble to ssocte rbtrr umber of eet ueues wth shred rble d cotrol the trsfers of processes to d fromthem geerl would therefore replce the preousproposl for codtol dels wth the followg oe

    he declrto

    vre vnt v;

    ssoctes eet queue wth shred rble v.

    1 The original soltio includes the folowing renementwhen a writer decides to make a request at most one moe readecan cmplete a reqest ahead o it. his can be ensured by srro.udg te eader. reqest in Agorithm 2 with an additionalctca regon assOCated with shared Boolean r.

    A process c lee crtcl rego ssocted wth d jo the eet ueue b executg the stdrdprocedure

    a wa (e)

    Aother process c eble ll processes the eetueue to reeter ther crtcl regos b executg thestdrd procedure

    causee)

    A cosumer/producer reltoshp must ow be expressed s follows

    onserrgion dobgin

    wil not B do awaie)SI

    nd

    Producerrgion do

    bgin

    nd

    2

    causee) ;

    Athough less elegt th the preous otto thepreset oe stll cler shows tht the cosumer swtg for codto to hold. Ad we c ow cotrolprocess schedulg to degree desred

    o smplf explct schedulg suggest tht proc

    esses reeterg ther crtcl regos fro eet ueuestke prort oer processes eterg crtc regos drect through m ueue (see Fgure . f the schedg rule s complete ukow to the progrmmer sefore ddtol rbles re reured to esure thtesources grted to wtg processes rem beto them utl the reeter ther crtcl regos

    Algorthm 3 s smple exmple of completel cotrolled resurce locto. A umbe ofprcesses shre pool of eulet resources Processes resourcesre deted b dces of tpe P d R respectelWhe resources re lbl, process c qur oemmedtel otherwse t must eter reuest dt

    structure of tpe s of P d wt utl resource sgtd to t t s ssumed tht the progrm cotrolsthe etr d remol of set elemets completel

    ommunicatiosof

    theAM

    July 1972Volume 15

    Nube

  • 8/3/2019 Structured Multi-programmIng, Per Brinch Hansen

    5/5

    Algoihm 3 heling of heavily se resores

    var v shar rodvilble st of Rjrequess st ofPjg array P of vnt Vj

    nd

    procdur reserveproess Pj var resoure R) jrion v doin whi empyvilble do

    in eerproess requess wigr[proessJ

    ndremoveresoure vilble

    nd

    procdur releseresoure R jvarproess Prion v doineerresoure vilblej

    if not empyrequess thnin removeproess requess

    usegrproess nd

    nd

    5 Concusion

    I have presente strtre ltiprograing onepts whih have siple aioati properties an peritetensive ople tie heking an generation of eient ahine oe

    The essential properties of these onepts are A istintion between isjoint an interating proesses;2 An assoiation of share ata with operations ene on the Mtal elsion of these operations in tie;4. ynhroniing priitives whih perit partial or

    oplete ontrol of press shelingThese are preisely the onepts neee to ipleentmonit poedues sh as the ones esribe in 8]They appear to be siently sae to se not only withinoperating systes bt also within ser progras to ontrol loal resores

    frns

    1.WiN. Te pogamming language Pascal A fomi

    1 (197135-63.2

    Binc HansenP An ouline of a couse on opeaing sysempinciples. Innaional Semina on peaing SysemTecniquesBelfasNoen elanAug-Sep. 19713

    HoaeAR Towas a eoy of paallel pogammingInenaional Semina on peaing Sysem TecniqueBelfasNoen IelanAugSep 1971

    4DijksaEW. oopeaing sequenial pocesses Tecnological

    V, inoven 96. Repine in Progmmig LggesF. Genys (Acaemic PessNew Yok1968

    onway M.E. A mulipocesso sysem esign Poc AFIPS1963 FJ ol 24Spaan Books,New Yokpp 13946

    8

    6ouoisP.JHeymansFan PanasD L oncuen

    conol wi "eaes an wies Comm. ACM 140(c 1971 667-6687.

    Binc HansenP A compaison of o synconizing concepsA ormi 1 3 1972,1901998

    Binc HansenP. Te nucleus of a mulipogamming sysemComm ACM 13 (Ap1970),238250

    ommunicaionsof

    eAM

    July 1972ume 1

    Nume