Sharedmemorymodel Processescommunicatebyapplyingoperationson - - PDF document

shared memory model
SMART_READER_LITE
LIVE PREVIEW

Sharedmemorymodel Processescommunicatebyapplyingoperationson - - PDF document

Sharedmemorymodel Processescommunicatebyapplyingoperationson andreceivingresponsesfrom sharedobjects Sharedmemory:PartI Asharedobjectisastatemachine States


slide-1
SLIDE 1

1 Sharedmemory:PartI

FDC SummerTerm2007

MaxPlanckInstituteforSoftware Systems

  • Sharedmemorymodel

Processescommunicatebyapplyingoperationson

andreceivingresponsesfromsharedobjects

Asharedobjectisastatemachine

States Operations/Responses Sequentialspecification

Examples:readwriteregisters,T&S,C&S,LLSC,…

  • Registers

Areadwriteregisterobject:

Storesvalues(inanorderedsetV) Exportstwooperations:readandwrite

WritetakesanargumentinVandreturnsok Readtakesnoargs andreturnsavalueinV

  • Sharedmemoryguarantees

Processesinvokeoperationsontheshared

  • bjectsand:

Liveness:theoperationseventuallyreturn

something

Safety:theoperationsneverreturn

anythingincorrect

  • Liveness

AnoperationiscompleteinarunRifits

invocationisfollowedbyaresponseinR

write(v)>ok read()>avalueinV

Aprocessinvokinganoperationmayfail

beforereceivingaresponse

Theliveness propertyinthisclass:inevery

run, everyoperationinvokedbyacorrect processiscomplete

  • Waitfreedom

Theliveness propertyinthisclass: Ineveryrun, everyoperationinvokedbya correctprocessiscomplete

slide-2
SLIDE 2

2

  • Asharedmemoryrun

p1 p2 p3

  • Safety(registers)

Informally,everyreadoperationreturnsthe “last” writtenvalue(theargumentofthe “last” writeoperation)

Whatis“last” ifoperationsmayoverlap

  • Asharedmemoryrun

p1 p2 p3

  • Operationprecedence

Operationop1issaidtoprecedeoperation

  • p2inarunRiftheresponseofop1

precedes(inglobaltime)theinvocationof

  • p2inR

Ifneitherop1precedesop2norop2

precedesop1thanop1andop2are concurrent

  • Operationprecedence

p1 p2 p3

  • Safetycriteria

Saferegisters:everyreadthatdoesnotoverlap

awritereturnsthelastwrittenvalue

Regularregisters:everyreadreturnsthelast

writtenvalue,ortheconcurrentlywrittenvalue (assumingonewriter)

Atomicregisters:regular+theoperationscanbe

totallyordered,preservingtheprecedence relation(strictlinearizability)

≈ ifread1returnsv,read2returnsv’,andread1 precedesread2,thenwrite(v’)cannotprecedewrite(v)

slide-3
SLIDE 3

3

  • Saferegister

p1 p2 p3

  • Regularregister

p1 p2 p3

  • Atomicregister

p1 p2 p3

  • Spaceofregisters

Values:frombinary(V={0,1})tomultivalued Numberofreadersandwriters:from1writer1

reader(1W1R)tomultiwritermultireader (NWNR)

Safetycriteria:fromsafetoatomic

1W1Rbinarysaferegisterscanbetransformed intoNWNRmultivaluedatomicregisters!

  • Outlineoftheclass

1.

1W1Rbinarysafe>1WNRbinarysafe

2.

1WNRbinarysafe>1WNRbinaryregular

3.

1WNRbinaryregular>1WNRmulti valuedregular

4.

AtomicNWNRregisters:definitions

  • 1W1R(binarysafe)>1WNR(binarysafe)

Letp1betheonlywriterand0betheinitialvalue Codeforprocesspi: initially: arrayR[1..N]of1W1Rregisters:=0N //Foralli,R[i]iswrittenbyp1andreadbypi uponread() returnR[i].read() uponwrite(v)//ifi=1 foralljdoR[j].write(v) returnok

slide-4
SLIDE 4

4

  • 1W1R(binarysafe)>1WNR(binarysafe)

Correctness:

enoughtoconsiderareadthatdoesnotoverlap

withanywrite

thelastwrittenvaluecannotbemissed

Worksalsoformultivaluedandregular

registers

  • 1WNRbinarysafe>1WNRbinaryregular

Letp1betheonlywriterand0betheinitialvalue Codeforprocessp1: initially: lv :=0\\ lastwrittenvalue uponwrite(v) ifv≠ lv then lv :=v foralljdoR[j].write(v) returnok

  • 1WNRbinarysafe>1WNRbinaryregular

Correctness:

R[]istouchedonlytochangethewrittenvalue =>both0and1arelegitimatevaluesincaseof concurrency

p1 p2

  • p3
  • Binary>Mvalued(1WNRregular)

Codeforprocesspi: initially: arrayR[0,..M1]of1WNRregisters:=[1,0,…,0] uponread() forj=0toM1do ifR[j].read()=1 then return(j) uponwrite(v)//ifi=1 R[v].write(1) forj=v1downto0doR[j].write(0) returnok

  • Binary>Mvalued(1WNRregular)

Correctness:

  • nlythelastorconcurrentlywrittenvaluecan

bereturned

HW:whatif: forj=0tov1doR[j].write(0) uponwrite(v)//ifi=1 forj=v1downto0doR[j].write(0) R[v].write(1) returnok

  • Histories

Ahistoryisasequenceofinvocationand responses

E.g.,p1>write(0),p2>read(),p1>ok,p2>0,…

Ahistoryissequentialifeveryinvocationis followedbyacorrespondingresponse

E.g.,p1>write(0),p1>ok,p2>read(),p2>0,… (Asequentialhistoryhasnoconcurrentoperations)

slide-5
SLIDE 5

5

  • Histories

p1 p2 p3

  • Histories

p1 p2 p3

  • Legalhistories

Asequentialhistoryislegal ifitsatisfiesthe sequentialspecificationoftheshared memory Readwriteregisters: Everyreadreturnstheargumentofthe lastwrite

  • Completeoperationsandcompletions

LetHbeahistory Anoperationopiscomplete inHifH containsboththeinvocationandthe responseofop Acompletion ofHisahistoryH’ that includesallcompleteoperationsofHanda subset ofincompleteoperationsofH followedwithmatchingresponses

  • Completeoperationsandcompletions

p1 p2 p3

  • !
  • Completeoperationsandcompletions

p1 p2 p3

slide-6
SLIDE 6

6

  • Strictlinearizability

AhistoryHisstrictlylinearizable ifthere existsH’,alegalsequentialcompletionof H,thatpreservestheprecedencerelation

  • fH:
  • p1precedesop2inH=>op1precedesop2

inH’

  • Atomicregister

Aregisterisatomic ifeveryhistoryit producesisstrictlylinearizable Informally,thecompleteoperations(and someincompleteoperations)areseenas takingeffectinstantaneouslyatsometime betweentheirinvocationsandresponses (Theoperationsareatomic)

  • Atomic?

p1 p2 p3

  • Atomic?

p1 p2 p3

  • "#$$%&'(
  • Atomic?

p1 p2 p3

  • Atomic?

p1 p2 p3

slide-7
SLIDE 7

7

  • Atomic?

p1 p2 p3

  • Atomic?

p1 p2 p3

  • From1W1Rregularto1W1Ratomic

p1 p2

  • )**
  • 1W1Rregular>1W1Ratomic

Codeforprocesspi: initially: shared1W1RregularregisterR:=0 localvariablest:=0,x:=0 uponread() (t’,x’):=R.read() ift’ >t then t:=t’;x:=x’; return(x) uponwrite(v)//ifi=1 t:=t+1 R.write(t,v)

  • Nextclass

Moretransformations

1W1Rsafebit>1W1Ratomicbit 1W1R>1WNR>NWNRatomicmultivalued

Assigningpapers