CS 541 Lecture -*- Outline -*- ** concurrent aspects of SR *** communication ------------------- SR COMMUNICATION MECHANISMS invoc service effect call proc (remote) procedure call call in rendezvous send proc dynamic process creation send in asynchronous message pass ------------------- draw the diagrams for each combination ------------------- OPERATION RESTRICTIONS limit how a op can be called: {send}, {call} {call, send} # default example: op multiply(i: int, j: int) {send} ------------------- important for some kinds of synchronization (e.g, for call, caller waits) *** abbreviations **** process ------------------ PROCESS DECLARATIONS process multiply(i := 1 to N, j := 1 to N) # body of multiply end meaning is: op multiply(i: int, j: int) {send} proc mutiply(i,j) # body of multiply end fa i := 1 to N, j := 1 to N -> send multiply(i,j) af ------------------ **** co ------------------ CONCURRENT INVOCATION co p(3) // q() // x := r(x,y) oc ------------------ abbreviates 3 process decls that make the calls not a general cobegin, can't be arbitrary statements ------------------ cnt := 0 co (i := 1 to n st a[i] != 0) p(i) -> cnt++; write(cnt, i) // (i := 1 to n st a[i] = 0) foo(i) -> write(i, " was 0") oc ------------------ quantifiers allow not writing out invocations separately the code following the -> is postprocessing code postprocessing blocks are executed one at a time, not concurrently execute in parent process ---------------- co (i := 1 to num_repls) fd[i].read(fn) -> which_one := i; exit oc ---------------- when any invocation terminates, execute postprocessing code for that one (recording which one) exit gets out of co without waiting for the others the others are not canceled, but "invoker does not get back their results" however their side effects still happen! **** in --------------- IN STATEMENT Syntax: in op_command [] op_command ... ni op_command ::= operation (formal_id_list) st synch_expr by sched_expr -> block | operation (formal_id_list) returns id st synch_expr by sched_expr -> block | else -> block --------------- can also subsript operation in operation command can also use quantifier to specify any one in a slice of an array synch_expr and sched_expr can reference formals --------------- Semantics: wait until some invocation is selectable (pending and synch_expr is true/omitted) pick oldest selectable (with minimum sched_expr) execute the corresponding block (return for a call is done when block ends) with else included, never wait if no op is selectable do the else block instead --------------- like Ada select in which each arm is an Ada accept else like Ada's otherwise but: SR allows synch_expr to refer to parameters of invocation Ada does not SR includes scheduling expression, Ada does not **** return, reply, forward ---------------- RETURN, REPLY, FORWARD return # call done, in or proc ends reply # call done, keeps going ---------------- from inside an `in' statement block return terminates a call, transmits any results, and continues from immediately after the ni reply terminates the call, transmits any results and continues with next statement ---------------- forward operation(expr, ...) # delegate to oper, keep going resource fun() op f(x: int) returns z: int op g(y: int) returns z: int process p var a := f(1); write(a) end proc f(x) returns z forward g(2*x) z := 3 # no effect write("in f") end proc g(y) returns z z := y + 10 end end ---------------- in the example: p calls f, f passes 2 to g and continues new process is created (as in send) for g(2) result of g is 12, returned from f(1), and assigned to a so this program writes 12 and "in f" (in some order) subsequent forwards are treated as sends. **** receive ---------------- RECEIVE STATEMENT abbreviation meaning receive f(v1, v2) in f(p1,p2) -> v1 := p1 v2 := p2 ni ---------------- so call and receive are like output and input commands of CSP **** semaphores ----------------- SEMAPHORES abbreviation meaning sem s op s() {send} P(s) receive s() V(s) send s() sem s := e op s() {send} var s_val := e fa i := 1 to s_val -> send s() af ------------------ ** distributed aspects *** virtual machines ------------------ VIRTUAL MACHINE - an address space - created dynamically using the vm pseudo-resource - can be placed on physical machine var flash: cap vm flash := create vm() on "flash" ------------------ default, if leave off "on" is to create it on same physical machine as the code executing the create can use integers or strings in expression following `on' ------------------ - has its own instance of any globals ------------------ so globals are only global to one vm *** program execution ------------------ SR PROGRAMS execution start: implicit creation of virtual machine on same physical machine implicit creation of main resource ------------------ main resource is one that is not imported by other resources specified when the program is linked (the last one on the command line to srl, or sr if not explicitly using srl) code in main resource, or in globals used by it (directly or indirectly), can create other vms and resources ------------------ execution termination: when - all processes have terminated, - a deadlock has occurred, - or stop is executed implicitly destroys main resource (unless stop had non-zero status) thus executing its final code ------------------ effect of stop is not instantaneous final code of main resource may destroy virtual machines this implicitly destroys all resources in those vms is every virtual machine part of some existing program? not necessarily, program can create a vm and not destroy it *** distributing vms and resources ------------------ DISTRIBUTING VIRTUAL MACHINES How: create vm() on expr where expr is a string ("flash") or an int locate(n, hostname) associates int n with hostname ---------------- by default, machine of main resource is 0, other names and number associations are conventional (defaults given SRMAP file, do man srmap for details) ---------------- Example: const hosts[2]: string[10] := ("f","s") fa i := 1 to 2 -> locate(i, hosts[i]) af # ... fa i := 1 to 3 -> vmcap[i] := create vm() on ((i mod 2) + 1) af ------------------ mymachine() gives number of physical machine where executed myvm() gives capability for vm on which executed ------------------ DISTRIBUTING RESOURCES AND GLOBALS Resources: create r(34) on expr where expr is a virtual machine capa and r is a resource name Examples: create Stack(20) on vmcap[1] create Stack(30) on myvm() create Stack(40) # here Globals: created as needed on each virtual mach when resource or global importing it is created ------------------ *** destruction ------------------ DESTRUCTION Of virtual machine: var flash: vm cap flash := create vm() on "flash" destroy flash Semantics: creation of new resources prevented each resource implicitly destroyed each global implicitly destroyed ------------------ error if try to destroy something already destroyed or null ok to destroy noop *** I/O stdout and stderr are global to program. inherited by new vms all other I/O specific to each virtual machine command line args also only available on main machine