9/10/2015CS2104, Lecture 81 Programming Language Concepts, COSC-3308-01 Lecture 8 (Multiple) Threads Semantics.

Slides:



Advertisements
Similar presentations
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Advertisements

Concurrent Programming Abstraction & Java Threads
1 CSC321 §2 Concurrent Programming Abstraction & Java Threads Section 2 Concurrent Programming Abstraction & Java Threads.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model From kernel to practical language (CTM 2.6) Exceptions (CTM.
DATAFLOW PROCESS NETWORKS Edward A. Lee Thomas M. Parks.
Slides 8d-1 Programming with Shared Memory Specifying parallelism Performance issues ITCS4145/5145, Parallel Programming B. Wilkinson Fall 2010.
Introduction to Computability Theory
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Road Map Introduction to object oriented programming. Classes
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Single assignment store Kernel language syntax Carlos Varela.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
Stacks. 2 What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
C. Varela; Adapted with permission from S. Haridi and P. Van Roy1 Declarative Concurrency (VRH4) Carlos Varela RPI Adapted with permission from: Seif Haridi.
Stacks (Revised and expanded from CIT 591). What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
CS 201 Functions Debzani Deb.
29-Jun-15 Java Concurrency. Definitions Parallel processes—two or more Threads are running simultaneously, on different cores (processors), in the same.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
S. Haridi and P. Van Roy1 Declarative Concurrency Seif Haridi KTH Peter Van Roy UCL.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
Computer Science Department Data Structure & Algorithms Lecture 8 Recursion.
Lecture 2 Foundations and Definitions Processes/Threads.
1 Exception Handling, Modules, Names Per Brand. 2 Exception Handling An exception is any expression E. To raise the exception, one executes the following.
1 Causal-Consistent Reversible Debugging Ivan Lanese Focus research group Computer Science and Engineering Department University of Bologna/INRIA Bologna,
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
Games Development 2 Concurrent Programming CO3301 Week 9.
Chapter 16 Recovery Yonsei University 1 st Semester, 2015 Sanghyun Park.
The Complexity of Distributed Algorithms. Common measures Space complexity How much space is needed per process to run an algorithm? (measured in terms.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
11/23/2015CS2104, Lecture 41 Programming Language Concepts, COSC Lecture 4 Procedures, last call optimization.
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
Java Thread and Memory Model
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
Concurrency Properties. Correctness In sequential programs, rerunning a program with the same input will always give the same result, so it makes sense.
Hwajung Lee. Well, you need to capture the notions of atomicity, non-determinism, fairness etc. These concepts are not built into languages like JAVA,
Hwajung Lee. Why do we need these? Don’t we already know a lot about programming? Well, you need to capture the notions of atomicity, non-determinism,
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Fall 2008Programming Development Techniques 1 Topic 20 Concurrency Section 3.4.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
1 Lecture 4: Concurrency Per Brand. 2 Threads and the store Store f Thread 1Thread 2Thread 3 Thread 4 ‘|’ Two runnable and two suspended threads Execution.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Agenda  Quick Review  Finish Introduction  Java Threads.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Chapter 3: Process Concept
CS 326 Programming Languages, Concepts and Implementation
Declarative Computation Model Kernel language semantics (Non-)Suspendable statements (VRH ) Carlos Varela RPI October 11, 2007 Adapted with.
Mini Language Interpreter Programming Languages (CS 550)
Chapter 19 Generics Dr. Clincy - Lecture.
Chapter 11: Classes, Instances, and Message-Handlers
Java Concurrency 17-Jan-19.
Stacks.
Introduction to Programming Concepts (VRH )
Declarative Computation Model Single assignment store (VRH 2
Java Concurrency.
Java Concurrency.
Threads and Multithreading
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Foundations and Definitions
Programming with Shared Memory Specifying parallelism
CS561 Computer Architecture Hye Yeon Kim
Java Concurrency 29-May-19.
Presentation transcript:

9/10/2015CS2104, Lecture 81 Programming Language Concepts, COSC Lecture 8 (Multiple) Threads Semantics

9/10/2015 CS2104, Lecture 8 2 Reminder of the Last Lecture abstract data types declarative concurrency design a concurrent program execution of concurrent programs

9/10/2015 CS2104, Lecture 8 3 Overview Thread Semantics Extend the abstract machine to execute multiple threads

9/10/2015CS2104, Lecture 84 Thread Semantics

9/10/2015 CS2104, Lecture 8 5 Semantics for Threads. (Interleaving Semantics) Interleaving: two different threads can interleave their computation steps Interleaving semantics:  Language viewpoint: threads can do interleaving execution; each computation step is atomic.  Implementation viewpoint: might execute several threads in parallel, however must execute as if one thread at a time; that is, whatever the parallel execution is, there is always at least one interleaving that is observationally equivalent to it.

9/10/2015 CS2104, Lecture 8 6 Causal Order of Computation Steps For a given program, all computation steps form a partial order, called the causal order. A computation step occurs before another step if in all possible executions of the program it happens before the other. Similarly for a computation step that occurs after another step. Sometimes a step is neither before nor after another step, that is, the two steps are concurrent.

9/10/2015 CS2104, Lecture 8 7 Causal Order and Interleaving Executions

9/10/2015 CS2104, Lecture 8 8 Declarative Nondeterminism Nondeterministic execution: there is an execution state in which there is a choice of what to do next, i.e., a choice of which thread to reduce. Example: After I a, there is a choice of either I 1 or I b Declarative concurrent model: the nondeterminism isn’t visible.  dataflow variables can be bound to only one value. The nondeterminism affects only the exact moment when each binding takes place; it does not affect the plain fact that the binding does take place.  any operation that needs the value of a variable has no choice but to wait until the variable is bound.

9/10/2015 CS2104, Lecture 8 9 Semantics for Threads (Scheduling) The choice of which thread to execute next is done by the scheduler. A thread is ready (or runnable), if its statement has all the information it needs to execute at least one computation step. Once a thread is ready, it stays ready indefinitely. So, thread reduction in declarative concurrent model is monotonic. A thread is suspended (or blocked), if it is not ready. That is, its first statement cannot continue because it does not have all the information it needs.

9/10/2015 CS2104, Lecture 8 10 Monotonicity (Example) thread if B then … else … end end When B is bound, thread will eventually run When B is bound, the value of B is fixed  value of B is independent of when thread executes

9/10/2015 CS2104, Lecture 8 11 Monotonicity: Simplicity Result is scheduling independent  unless attempt to put inconsistent information to store  Example: non-determinism ( failure exception) thread X=1 end thread X=2 end  which value for X ? Different with explicit mutable state (JAVA)  if variable values changed over time, result would depend on order in which threads run

9/10/2015 CS2104, Lecture 8 12 Dependencies Suspension and resumption driven by variable bindings Progress, only if for each variable, its value is supplied Typical error-scenario: deadlock  thread depends on X, supposed to bind Y  thread depends on Y, supposed to bind X Example: declare X Y thread if X==1 then Y=1 {Browse 1} end end thread if Y==1 then X=1 {Browse 2} end end

9/10/2015 CS2104, Lecture 8 13 Extend Abstract Machine Extend to execute multiple threads  shared store: all threads share common store  semantic stack: corresponds to a thread  thread creation: create a new semantic stack Orthogonal: scheduling policy  scheduling policy: which thread to execute?  consider only non-suspended threads!

9/10/2015 CS2104, Lecture 8 14 Abstract Machine Concepts (Reminder) Single-assignment store Environment Semantic statement Execution state Computation

9/10/2015 CS2104, Lecture 8 15 Abstract Machine (Reminder) Performs a computation Computation is a sequence of execution states Execution state  stack of semantic statements  single assignment store Semantic statement  statement  environment Environment maps variable identifiers to store entities

9/10/2015 CS2104, Lecture 8 16 Single Assignment Store (Reminder) Single assignment store   set of store variables  partitioned into sets of variables that are equal but unbound variables bound to value Example store{x 1, x 2 =x 3, x 4 = a |x 2 }  x 1 unbound  x 2, x 3 equal and unbound  x 4 bound to partial value a |x 2

9/10/2015 CS2104, Lecture 8 17 Environment (Reminder) EnvironmentE  maps variable identifiers to entities in store   written as set of pairs X  x variable identifier X store variablex Example environment{ X  x, Y  y }  maps identifier X to store variable x  maps identifier Y to store variable y

9/10/2015 CS2104, Lecture 8 18 Environment and Store (Reminder) Given: environment E, store  Looking up value for variable identifier X :  find store variable in environmentE( X )  take value from  for E( X ) Example:  ={x 1, x 2 =x 3, x 4 = a |x 2 } E = { X  x 1, Y  x 4 }  E( X ) = x 1 and no information in  on x 1  E( Y ) = x 4 and  binds x 4 to a |x 2

9/10/2015 CS2104, Lecture 8 19 Environment Adjunction (Reminder) Given: Environment E E + {  x  1  x 1, …,  x  n  x n } is new environment E ’ with mappings added:  always take store entity from new mappings  might overwrite old mappings

9/10/2015 CS2104, Lecture 8 20 Semantic Statements (Reminder) To actually execute statement:  environment to map identifiers modified with execution of each statement each statement has its own environment  store to find values all statements modify same store single store Semantic statement(  s , E )  pair of (statement, environment)

9/10/2015 CS2104, Lecture 8 21 Semantic Stack (Reminder) Execution maintains stack of semantic statementsST [(  s  1, E 1 ), …, (  s  n, E n )]  always topmost statement (  s  1, E 1 ) executes first  rest of stack: what needs to be done

9/10/2015 CS2104, Lecture 8 22 Semantic Stack States (Reminder) Semantic stack can be in run-time states  terminatedstack is empty  runnablecan do execution step  suspendedstack not empty, no execution step possible Statements  non-suspendingcan always execute  suspendingneed values from store dataflow behavior

9/10/2015 CS2104, Lecture 8 23 Summary Single assignment store  EnvironmentsE  adjunctionE + {…} Semantic statements(  s , E) Semantic stacks[(  s , E) … ] Execution state(ST,  ) Program execution  runnable, terminated, suspended Statements  suspending, non-suspending

9/10/2015 CS2104, Lecture 8 24 Executing if (Reminder) Semantic statement is ( if  x  then  s  1 else  s  2 end, E) If activation condition “  x  bound” is true  if E(  x  ) bound to true push  s  1  if E(  x  ) bound to false push  s  2  otherwise, raise error Otherwise, suspend…

9/10/2015 CS2104, Lecture 8 25 Procedure Call (Reminder) Semantic statement is ( {  x   y  1 …  y  n }, E) where  E(  x  ) is to be called   y  1, …,  y  n are actual parameters Suspending statement, suspension condition  E(  x  ) is determined

9/10/2015 CS2104, Lecture 8 26 Summary so far Semantic statement executes by  popping itselfalways  creating environment local  manipulating store local, =  pushing new statements local, if sequential composition Semantic statement can suspend  activation condition if, {…}, case  read store

9/10/2015 CS2104, Lecture 8 27 Multiple Semantic Stacks Abstract machine has multiple semantic stacks  each semantic stack represents one thread Number of semantic stacks change over time  increases:new threads created  decreases:threads terminate

9/10/2015 CS2104, Lecture 8 28 Multisets Collection of semantic stacks called multiset of semantic stacks Multiset: like a set, but maintains multiplicity  ordinary set: element can be contained at most once {1,2,3}  multiset: element can be contained many times {1,1,1,2,2,3} is different from {1,1,2,3,3}  just think of: bag, collection, bunch of something  same thread is allowed to occur more than once

9/10/2015 CS2104, Lecture 8 29 Execution State ( Multiset of semantic stacks, store ) ({ ST 1, …, ST n },  ) we write multisets with normal set parentheses: { and }

9/10/2015 CS2104, Lecture 8 30 Execution State ( Multiset of semantic stacks, store ) ({ ST 1, …, ST n },  ) MST Multisets of stacks are denotedMST

9/10/2015 CS2104, Lecture 8 31 Initial Execution State Given statement  s , start execution as before with empty environment, empty store and just one thread ( { [ (  s ,  ) ] },  )

9/10/2015 CS2104, Lecture 8 32 Initial Execution State Given statement  s , start execution as before with empty environment, empty store and just one thread ( { [ (  s ,  ) ] },  ) execution state

9/10/2015 CS2104, Lecture 8 33 Initial Execution State Given statement  s , start execution as before with empty environment, empty store and just one thread ( { [ (  s ,  ) ] },  ) store (empty)

9/10/2015 CS2104, Lecture 8 34 Initial Execution State Given statement  s , start execution as before with empty environment, empty store and just one thread ( { [ (  s ,  ) ] },  ) multiset of threads (just one)

9/10/2015 CS2104, Lecture 8 35 Initial Execution State Given statement  s , start execution as before with empty environment, empty store and just one thread ( { [ (  s ,  ) ] },  ) thread (just one)

9/10/2015 CS2104, Lecture 8 36 Initial Execution State Given statement  s , start execution as before with empty environment, empty store and just one thread ( { [ (  s ,  ) ] },  ) semantic statement

9/10/2015 CS2104, Lecture 8 37 Initial Execution State Given statement  s , start execution as before with empty environment, empty store and just one thread ( { [ (  s ,  ) ] },  ) statement (initial)

9/10/2015 CS2104, Lecture 8 38 Initial Execution State Given statement  s , start execution as before with empty environment, empty store and just one thread ( { [ (  s ,  ) ] },  ) empty environment

9/10/2015 CS2104, Lecture 8 39 Execution Execution steps (MST 1,  1 )  (MST 2,  2 )  … At each step  select runnable semantic stack ST i from MST i  execute topmost semantic statement of ST i resulting in ST’ i  continue with threads MST i+1 = {ST’ i }  (MST i – {ST i })

9/10/2015 CS2104, Lecture 8 40 Execution Execution steps (MST 1,  1 )  (MST 2,  2 )  … At each step  select runnable semantic stack ST i from MST i  execute topmost semantic statement of ST i resulting in ST’ i  continue with threads MST i+1 = {ST’ i }  (MST i – {ST i })

9/10/2015 CS2104, Lecture 8 41 Statements  s  ::= skip |  x  =  y  |  x  =  v  |  s  1  s  2 | local  x  in  s  end | if  x  then  s  1 else  s  2 end | {  x   y  1 …  y  n }

9/10/2015 CS2104, Lecture 8 42 Statements with Thread Creation  s  ::= skip |  x  =  y  |  x  =  v  |  s  1  s  2 | local  x  in  s  end | if  x  then  s  1 else  s  2 end | {  x   y  1 …  y  n } | thread  s  end

9/10/2015 CS2104, Lecture 8 43 Sketch of Computation Multiple threads sharing store  ST 1 ST n …

9/10/2015 CS2104, Lecture 8 44 Sketch of Computation Thread creation statement…  ST n … ST i (thread  s  end, E )

9/10/2015 CS2104, Lecture 8 45 Sketch of Computation …new semantic stack running  s   ST n … ST i (  s ,E)

9/10/2015 CS2104, Lecture 8 46 Example local B X in thread if B then X=1 else X=2 end end B=true end

9/10/2015 CS2104, Lecture 8 47 The Abstract Machine with Threads ( { [ ( local B X in thread if B then X=1 else X=2 end end B=true end,  ) ] },  ) We need to apply the local statement

9/10/2015 CS2104, Lecture 8 48 The Abstract Machine with Threads ( { [ ( thread if B then X=1 else X=2 end end B=true, { B  b, X  x }) ] }, { b, x } ) We need to apply the sequential composition

9/10/2015 CS2104, Lecture 8 49 The Abstract Machine with Threads ( { [ ( thread if B then X=1 else X=2 end end, { B  b, X  x }) ( B=true, { B  b, X  x }) ] }, { b, x } ) We need to apply thread … end

9/10/2015 CS2104, Lecture 8 50 The Abstract Machine with Threads ( { [ ( if B then X=1 else X=2 end, { B  b, X  x }) ] [ ( B=true, { B  b, X  x }) ] }, { b, x } ) We need to select a runnable semantic stack from the multiset of semantic stacks First semantic stack cannot run because B is unbound!

9/10/2015 CS2104, Lecture 8 51 The Abstract Machine with Threads ( { [ ( if B then X=1 else X=2 end, { B  b, X  x }) ] [ ] }, { b= true, x } ) After we run the second semantic stack The first semantic stack can run now because the if statement is not suspended anymore!

9/10/2015 CS2104, Lecture 8 52 The Abstract Machine with Threads ( { [ ( X=1, { B  b, X  x }) ] [ ] }, { b= true, x } ) We need to execute the variable-value equality

9/10/2015 CS2104, Lecture 8 53 The Abstract Machine with Threads ( { [ ] [ ] }, { b= true, x= 1 } ) We conclude that B and X have been bound to true and 1, respectively.

9/10/2015 CS2104, Lecture 8 54 Statements with Thread Creation  s  ::= skip |  x  =  y  |  x  =  v  |  s  1  s  2 | local  x  in  s  end | if  x  then  s  1 else  s  2 end | {  x   y  1 …  y  n } | thread  s  end | {ByNeed  x   y  }

9/10/2015 CS2104, Lecture 8 55 Sketch of Computation Thread creation statement…  ST n … ST i ({ByNeed  x   y  }, E )

9/10/2015 CS2104, Lecture 8 56 Sketch of Computation The store is  the variable-store +  the trigger- store  ST n … ST i ({ByNeed  x   y  }, E ) 

9/10/2015 CS2104, Lecture 8 57 Triggers A by-need trigger is a pair trig(F, X) :  a zero-argument function F  a variable X Additionally to single-assignment store , we consider a new store , called the trigger-store The trigger store contains all by-need triggers and is initially empty. The execution state becomes a triple (MST, ,  ).

9/10/2015 CS2104, Lecture 8 58 Trigger Creation (Executing ByNeed ) Semantic statement is ({ ByNeed  x   y  }, E)   x  is a one-argument procedure   y  is a variable If  y  is not determined (unbound)  Add the trigger trig( E(  x  ), E(  y  ) ) to the trigger store If  y  is determined (bound)  Create a new thread with initial semantic stack [({  x   y  }, E)]

9/10/2015 CS2104, Lecture 8 59 Trigger Activation (Executing ByNeed ) If trig(x, y) is in the trigger-store and a need on y is detected, then  there is either a thread that is suspended waiting for y to be determined, or  an attempt to bind y to make it determined then  Remove the trigger from the trigger store.  Create a new thread with initial semantic stack: [ ({ },{  x,  y}) ]  {…} is a procedure call!

9/10/2015 CS2104, Lecture 8 60 The Abstract Machine with By-Need ( { [ ( local X Z in X={ByNeed fun {$} 4 end} {Browse X} Z=X+1 end,  ) ] }, ,  )  is the trigger-store We need to apply the local statement

9/10/2015 CS2104, Lecture 8 61 The Abstract Machine with By-Need ( { [ ( X={ByNeed fun {$} 4 end} {Browse X} Z=X+1, { X  x, Z  z }) ] }, { x, z },  ) We need to apply the sequential composition

9/10/2015 CS2104, Lecture 8 62 The Abstract Machine with By-Need ( { [ ( X={ByNeed fun {$} 4 end}, { X  x, Z  z }) ( {Browse X} Z=X+1, { X  x, Z  z }) ] }, { x, z },  ) We need to apply the trigger creation

9/10/2015 CS2104, Lecture 8 63 The Abstract Machine with By-Need ( { [( {Browse X} Z=X+1, { X  x, Z  z }) ] }, { x, z }, trig ( fun {$} 4 end, x )) We need to apply the sequential composition

9/10/2015 CS2104, Lecture 8 64 The Abstract Machine with By-Need ( { [( {Browse X}, { X  x, Z  z }) ( Z=X+1, { X  x, Z  z }) ] }, { x, z }, trig ( fun {$} 4 end, x )) Browse visualizes the single-assignment store in the Browser window In fact, Browse is running in a system’s thread!

9/10/2015 CS2104, Lecture 8 65 The Abstract Machine with By-Need ( { [( {Browse X}, { X  x, Z  z })] [( Z=X+1, { X  x, Z  z })] }, { x, z }, trig ( fun {$} 4 end, x )) From this multiset of threads, Browse is suspended since X is unbound Executing the second semantic stack, X is needed because it appears in the right-hand side of Z=X+1, so trig (…, x ) is removed from  and we create a new thread

9/10/2015 CS2104, Lecture 8 66 The Abstract Machine with By-Need ( { [({ fun {$} 4 end X },{ X  x })] [( {Browse X}, { X  x, Z  z })] [( Z=X+1, { X  x, Z  z })] }, { x, z },  ) The second and third semantic stacks are suspended We executed the first semantic stack

9/10/2015 CS2104, Lecture 8 67 Zero-Argument Function’s Call local X in {fun {$} 4 end X} {Browse X} end X is an output argument for an anonymous procedure  4 4 Is equivalent with local X Fun1 in proc {Fun1 Result1} Result1 = 4 end {Fun1 X} {Browse X} end

9/10/2015 CS2104, Lecture 8 68 The Abstract Machine with By-Need ( {[( {Browse X}, { X  x, Z  z })] [( Z=X+1, { X  x, Z  z })] }, { x= 4, z },  ) Any thread can run now If executing the first semantic stack, then the browser will display 4 If executing the second semantic stack, then …

9/10/2015 CS2104, Lecture 8 69 The Abstract Machine with By-Need ( { }, { x= 4, z= 5 },  ) The execution stops by binding x to 4 and z to 5

9/10/2015 CS2104, Lecture 8 70 A Variable is Needed if Must be Determined thread X={ByNeed fun {$} 3 end} end thread Y={ByNeed fun {$} 4 end} end thread Z=X+Y end Considering that each thread executes atomically, there are six possible executions. For lazy execution to be declarative, all of these executions must lead to equivalent stores. The addition will wait until the other two triggers are created, and these triggers will then be activated.

9/10/2015 CS2104, Lecture 8 71 A Variable is Needed if it is Determined thread X={ByNeed fun {$} 3 end} end thread X=2 end thread Z=X+4 end The correct behavior of the declarative demand-driven concurrent model is that all executions should fail. If X=2 executes last, then the trigger has already been activated, binding X to 3, so this is clear. But if X=2 is executed first, then the trigger should also be activated.

9/10/2015 CS2104, Lecture 8 72 Garbage Collection of Threads If a thread is known to be suspended forever, it can be garbage-collected  suspends on variable not in use by any other thread  does not change semantics, just saves memory Approximation, only straight-forward cases  impossible: detect whether a thread will have no effect!  really impossible!

9/10/2015 CS2104, Lecture 8 73 Summary so far Threads are organized as multiset of semantic stacks Thread creation inserts new semantic stack  inherits environment  shares store Thread termination removes threads

9/10/2015 CS2104, Lecture 8 74 Summary Thread Semantics Extend the abstract machine to execute multiple threads

9/10/2015 CS2104, Lecture 8 75 Reading suggestions From [van Roy,Haridi; 2004]  Chapter 4, Sections  Exercises

9/10/2015 CS2104, Lecture 8 76 Coming up next Stateful programming Object-Oriented Programming  Chapter 5, Sections

9/10/2015 CS2104, Lecture 8 77 Thank you for your attention! Questions?