Download presentation
Presentation is loading. Please wait.
Published byBlaze Williams Modified over 9 years ago
1
Modelling III: Asynchronous Shared Memory Model Chapter 9 by Nancy A. Lynch presented by Mark E. Miyashita
2
Introduction Shared Memory System Environment Model Shared Variable Types Failures Organization
3
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
4
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
5
Shared Memory System portsprocessesShared variables 1 2 n Figure 9.1: An asynchronous shared memory system 1 2 n
6
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
7
Shared Memory System Assume shared memory system consisting of n processes numbered 1,….,n Assume each process ì has an associated set of states, states i, among which some are designated as the start states, start i Assume each shared variable x in the system has an associated values, values x, among which some are designated as the initial values, initial x Each state in state(A) consists of a state in states i for each process ì and a value in values x for each shared variable x Each state in start(A) consists of a state in start i for each process ì and a value in initial x for each shared variable x
8
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
9
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’ states i –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’ states i and v,v’ values x
10
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
11
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 1.For any ì, if exactly one init ì event appears in , then exactly one decide ì event appears in 2.For any ì, if no init ì event appears in , then no decide ì event appears in 3.(Agreement) If decide(v) ì and decide(w) j both appear in , then v=w 4.(Validity) if a decide(v) ì appears in , then some init(v) j event (for the same v) appears in
12
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 ì
13
portsprocessesShared variables 1 2 n init(v) 1 Environment model x decide(v) 1 U1U1 U2U2 UnUn users
14
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
15
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 1.For any ì, contains exactly one init ì event follow by exactly one decide ì event 2.(Agreement) If decide(v) ì and decide(w) j both appear in , then v=w 3.(Validity) if a decide(v) ì appears in , then some init(v) j event (for the same v) appears in
16
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 v 0 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
17
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
18
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
19
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
20
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
21
Read-modify-write Shared Variable One instantaneous read-modify-write operation on a shared variable x, a process ì can do all of the following: 1.Read x 2.Carry out some computation, possible using the value of x, that modifies the state of ì and determines a new value for x 3.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
22
Read-modify-write Shared Variable Example 9.1.1, the function submitted by a process to the variable is of the form h v where v, if x = unknown h v (x) = x, otherwise h v 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
23
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
24
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
25
Failures portsprocessesShared variables 1 1 2 n 2 n stop n 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.