250 likes | 361 Views
Modelling III: Asynchronous Shared Memory Model Chapter 9 by Nancy A. Lynch presented by Mark E. Miyashita. Organization. Introduction Shared Memory System Environment Model Shared Variable Types Failures. Introduction.
E N D
Modelling III: Asynchronous Shared Memory ModelChapter 9by Nancy A. Lynchpresented by Mark E. Miyashita
Organization • Introduction • Shared Memory System • Environment Model • Shared Variable Types • Failures
Introduction • The model is presented in terms of the general I/O automaton model for asynchronous systems as defined from the previous chapter • As oppose to previous chapter where sending and receiving messages over communication channels, a shared memory system consists of a collection of communicating processes performing instantaneous operations on shared variables
Shared Memory System • Informally, an asynchronous memory system consists of a finite collection of processes interacting with each other by means of a finite collection of shared variables • These variables are used only for communication among the processes in the system • Assume in this model that each process has a port which can interact with outside world (environment) using input and output actions • The model consists of single I/O automaton with its external interface consisting of the input and output actions on all the ports • It does not use several automata for one per process and one per shared variables
Shared Memory System ports processes Shared variables 1 Figure 9.1: An asynchronous shared memory system 1 2 2 n n
Shared Memory System • Why? Using I/O automaton composition, resulting system obtained will have operation by a process ì on a shared variable x would be modelled by a pair of events – invocation and response • One of the possible executions could be an invocation that is an output of process ì and an input of variable x, followed by a response that is an output of variable x and an input of process ì • Another possible executions can split these pair of events – several operations could be invoked before the first of them returning • Avoiding issues above by modelling the entire system as one big I/O automaton A which captures the process and variable structure within A
Shared Memory System • Assume shared memory system consisting of n processes numbered 1,….,n • Assume each process ì has an associated set of states, statesi, among which some are designated as the start states, starti • Assume each shared variable x in the system has an associated values, valuesx, among which some are designated as the initial values, initialx • Each state in state(A) consists of a state in statesi for each process ì and a value in valuesx for each shared variable x • Each state in start(A) consists of a state in starti for each process ì and a value in initialx for each shared variable x
Shared Memory System • Assume each action in acts(A) is associated with one of the process • Int(A) may be associated with a shared variables – two cases to consider • Both input and output actions associated with process ì are used for both interactions between process ì and outside world (occur on port ì); shared variable x is used for performing operations on x • Processes ì without associated shared variables are used for internal computation
Shared Memory System • The set tans(A) of transitions has some locality restrictions with two cases to consider as int(a) • An action that is associated with process ì without variable (local computation) – only the state of ì can be involved in any step – the set of triples of form (s, , s’), where s, s’ statesi • An action that is associated with both process ì and a variable x ( is used by ì to perform operation on x) - only the state of ì and value of x can be involved in any step – the set of triples of form ((s,v), , (s’,v’)), where s,s’ statesi and v,v’ valuesx
Shared Memory System States of ì: Status {idle,access,decide,done}, initially idle Input V {unknown}, initially unknown Output V {unknown}, initially unknown Transitions of ì: Init(v)ì decide(v)ì Effect: Precondition: input := v status = decide if status = idle then status := access output = v accessì Effect: Precondition: status := done status = access Effect: if x = unknown then x := input output := x status := decide
Shared Memory System • Let P be the trace property such that sig(P) = extsig(P) and trances(P) is the set of sequences of actions in acts(P) satisfying • For any ì, if exactly one initì event appears in , then exactly one decideì event appears in • For any ì, if no initì event appears in , then no decideì event appears in • (Agreement) If decide(v)ì and decide(w)j both appear in , then v=w • (Validity) if a decide(v)ì appears in , then some init(v)j event (for the same v) appears in
Environment model • It model the environment of a system as an automaton in addition to previous example • It allows way to describe assumptions about the environment’s behavior • For practical shared memory system, the environment can be described as a collection of independent user automaton, one per port • Extending the previous example, the environment is a single I/O automaton that is composed of one user automaton Uì, for each process index ì
Environment model users ports processes Shared variables init(v)1 U1 1 decide(v)1 U2 2 x Un n
Environment model Signature: Input: decide(v)ì, v V Internal: dummyì Output: init(v)ì, v V States: Status {request,wait,done}, initially request Decision V {unknown}, initially unknown error, a boolean, initially false Transitions: Init(v)ì decide(v)ì Precondition: Effect: status = request or error = true if error = false then Effect: if status = wait then if error = false then status := wait decision := v status := done dummyì else error := true Precondition: error = true Effect: none
Environment model • Let Q be the trace property such that sig(Q) consists of output init(v)ì and decide(v)ì for all ì and v, and trances(Q) is the set of sequences of actions in acts(Q) satisfying • For any ì, contains exactly one initì event follow by exactly one decideì event • (Agreement) If decide(v)ì and decide(w)j both appear in , then v=w • (Validity) if a decide(v)ì appears in , then some init(v)j event (for the same v) appears in
Shared Variable Types • A variable type consists of (what it means of shared memory system A to observe type restrictions) • a set V of values • an initial value v0 V • a set of invocations • a set of response • a function f: invocation x V responses x V • The function f indicates when a given invocation arrives at the variable and the variable has a given value; f describes the new value the variable assigned and the response that is returned • The invocations and responses are thought of as occurring together as part of one function as oppose to the input/outputs actions of I/O automaton model are separate
Shared Variable Types For each process ì and invocation a, the set of transitions involving ì and a must be describable in the form where p is some predicate on stateì and g is some relation: g stateì x response x stateì Transition involving ì and a Precondition: p(stateì) Effect: (b,x) := f(a,x) stateì := any s such that (stateì,b,s) g The function f for the variable type is applied to the invocation a and the value of variable x to determine a response b and a new value for x
Read/Write Shared Variable • Most frequently used variable type in multiprocessors is one supporting only read and write operations • Invocations are read and write(v), v V • Responses are v V and ack • Function f : f(read,v) = (v,v) and f(write(v),w) = (ack, v) • Rewriting algorithm of Example 9.1.1 by separating each access into a read and write step • The status value access is replaced by two new status values, read and write
Read/Write Shared Variable Transitions: Init(v)ì decide(v)ì Effect: Precondition: input := v status = decide if status = idle then status := read output = v readì Effect: Precondition: status := done status = read Effect: write(v)ì if x = unknown then Precondition: output := input status = write status := write v = input else Effect: output := x x := v status := decide status := decide
Read/Write Shared Variable Re-writing code in terms of a predicate p and a relation g; readì action p is simply “status = read” relation g is the set of triplets (s,b,s’) stateì x (V{unknown}) x stateì s’ is obtained from s by the code if b = unknown then output := input status := write else output := b status := decide write(v)ì action p is simply “status = write and v = input” relation g is the set of triplets (s,b,s’) stateì x (V{unknown}) x stateì s’ is obtained from s by the code status := decide
Read-modify-write Shared Variable • One instantaneous read-modify-write operation on a shared variable x, a process ì can do all of the following: • Read x • Carry out some computation, possible using the value of x, that modifies the state of ì and determines a new value for x • Write the new value to x • The function h used as an invocation of the variable, it provides the information from the process’s state that is needed to determine the transition, expressed in the form of a function to apply to the variable • Its invocation are all the functions h, where h: V V • Its responses are v V • Function f: f(h,v)= (v,h(v)) – it responds with prior value and updates its values based on the submitted function
Read-modify-write Shared Variable • Example 9.1.1, the function submitted by a process to the variable is of the form hv where • v, if x = unknown • hv(x) = x, otherwise • hv submitted by a process uses the process’s input as the value of v • A return value of unknown cases input to be set to the value of output • A return value of v V causes output to be set to v
Other Variable types • Compare-and-swap • Invocation are of the form compare-and-swap(u,v), u,v, V • Responses are elements of V • Function f is defined as: • (w,v), if u=w • f(compare-and-swap(u,v),w) = (w,w), otherwise • If the variable’s value is equal to the first argument u, then operation resets it to the second argument v; otherwise operation does not change the value of variable • Swap • Invocation are the form swap(u), u V • Responses are elements of V • Function f is defined as: • f(swap(u),v) = (v,u) – write input value u into variable and returns original variable value v
Other Variable types • test-and-set • Invocation are of the form test-and-set • Responses are elements of V (assume 1 V) • Function f is defined as: f(test-and-set,v = (v,1) • The operation writes 1 into the variable and returns the original value v • Fetch-and-add • Invocation are the form fetch-and-add(u), u V • Responses are elements of V • Function f is defined as: f(fetch-and-add(u),v) = (v,v+u) • The operation adds the input value u to the variable value v and returns the original value v
Failures • a stopì (input action) event can change only the state of process ì, disable all the tasks of process ì • Effect of such state changes never be communicated to any other process ports processes Shared variables 1 1 2 2 stopn n n