Carlos Varela Rennselaer Polytechnic Institute October 6, 2017

Slides:



Advertisements
Similar presentations
Interactive lesson about operating system
Advertisements

Agents & Mobile Agents.
Models of Concurrency Manna, Pnueli.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Introduction CSCI 444/544 Operating Systems Fall 2008.
C. Varela1 Actors (PDCS 4) AMST actor language syntax, semantics, join continuations Carlos Varela Rennselaer Polytechnic Institute April 16, 2015.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
1: Operating Systems Overview
Concurrency CS 510: Programming Languages David Walker.
An introduction to F# (part 2) Bogdan Brinzarea-Iamandi Banca Romaneasca 25 February 2010.
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
Mobile Ambients Luca Cardelli Digital Equipment Corporation, Systems Research Center Andrew D. Gordon University of Cambridge, Computer Laboratory Presented.
1 Testing Concurrent Programs Why Test?  Eliminate bugs?  Software Engineering vs Computer Science perspectives What properties are we testing for? 
(C) 2009 J. M. Garrido1 Object Oriented Simulation with Java.
SALSA: Language and Architecture for Widely Distributed Actor Systems. Carlos Varela, Abe Stephens, Department of.
Multi-Threaded Application CSNB534 Asma Shakil. Overview Software applications employ a strategy called multi- threaded programming to split tasks into.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
The Complexity of Distributed Algorithms. Common measures Space complexity How much space is needed per process to run an algorithm? (measured in terms.
C. Varela1 Actors in SALSA and Erlang (PDCS 9, CPE 5*) Support for actor model in SALSA and Erlang Carlos Varela Rennselaer Polytechnic Institute October.
C. Varela1 Chapter 4: Actors Programming Distributed Computing Systems: A Foundational Approach Carlos Varela Rensselaer Polytechnic Institute.
Introduction.  Administration  Simple DBMS  CMPT 454 Topics John Edgar2.
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,
C. Varela1 Distributed systems abstractions (PDCS 9, CPE 6*) Carlos Varela Rennselaer Polytechnic Institute October 20, 2015 * Concurrent Programming in.
Fall 2008Programming Development Techniques 1 Topic 20 Concurrency Section 3.4.
C H A P T E R E L E V E N Concurrent Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
SystemC Semantics by Actors and Reduction Techniques in Model Checking Marjan Sirjani Formal Methods Lab, ECE Dept. University of Tehran, Iran MoCC 2008.
Agenda  Quick Review  Finish Introduction  Java Threads.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
Processes and threads.
Advanced Operating Systems CIS 720
Chapter 3: Process Concept
Mobile Ambients Luca Cardelli Andrew D. Gordon Pravin Shetty
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Processes and Threads Processes and their scheduling
Distributed systems abstractions (PDCS 9, CPE 6*)
Multithreaded Programming in Java
CS399 New Beginnings Jonathan Walpole.
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Processes Overview: Process Concept Process Scheduling
Chapter 3: Process Concept
Rennselaer Polytechnic Institute
New trends in parallel computing
CMSC 611: Advanced Computer Architecture
Lecture 2: Processes Part 1
Recap OS manages and arbitrates resources
Transactional Memory Semaphores, monitors, and conditional critical regions all suffer from limitations based on lock semantics Naïve synchronization may.
Distributed (Systems) Programming Universal Actors, SALSA, World-Wide Computer Carlos Varela RPI C. Varela.
Multiple Processor Systems
Threading And Parallel Programming Constructs
Concurrency control abstractions (PDCS 9, CPE 5*)
Declarative Concurrency (CTM 4)
Background and Motivation
Carlos Varela Rennselaer Polytechnic Institute October 4, 2016
Multithreaded Programming
Subject : T0152 – Programming Language Concept
Introduction to Programming Concepts (VRH )
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CS510 Operating System Foundations
Foundations and Definitions
Concurrent Programming Actors, SALSA, Coordination Abstractions
Chapter 3: Process Management
Presentation transcript:

Carlos Varela Rennselaer Polytechnic Institute October 6, 2017 Actors (PDCS 4) AMST actor language syntax, semantics, join continuations Carlos Varela Rennselaer Polytechnic Institute October 6, 2017 C. Varela

Advantages of concurrent programs Reactive programming User can interact with applications while tasks are running, e.g., stopping the transfer of a big file in a web browser. Availability of services Long-running tasks need not delay short-running ones, e.g., a web server can serve an entry page while at the same time processing a complex query. Parallelism Complex programs can make better use of multiple resources in new multi-core processor architectures, SMPs, LANs, WANs, grids, and clouds, e.g., scientific/engineering applications, simulations, games, etc. Controllability Tasks requiring certain preconditions can suspend and wait until the preconditions hold, then resume execution transparently. C. Varela

Disadvantages of concurrent programs Safety « Nothing bad ever happens » Concurrent tasks should not corrupt consistent state of program. Liveness « Anything ever happens at all » Tasks should not suspend and indefinitely wait for each other (deadlock). Non-determinism Mastering exponential number of interleavings due to different schedules. Resource consumption Threads can be expensive. Overhead of scheduling, context-switching, and synchronization. Concurrent programs can run slower than their sequential counterparts even with multiple CPUs! C. Varela

Overview of concurrent programming There are four basic approaches: Sequential programming (no concurrency) Declarative concurrency (streams in a functional language) Message passing with active objects (Erlang, SALSA) Atomic actions on shared state (Java) The atomic action approach is the most difficult, yet it is the one you will probably be most exposed to! But, if you have the choice, which approach to use? Use the simplest approach that does the job: sequential if that is ok, else declarative concurrency if there is no observable nondeterminism, otherwise use actors and message passing. C. Varela

Actors/SALSA Actor Model SALSA A reasoning framework to model concurrent computations Programming abstractions for distributed open systems G. Agha, Actors: A Model of Concurrent Computation in Distributed Systems. MIT Press, 1986. Agha, Mason, Smith and Talcott, “A Foundation for Actor Computation”, J. of Functional Programming, 7, 1-72, 1997. SALSA Simple Actor Language System and Architecture An actor-oriented language for mobile and internet computing Programming abstractions for internet-based concurrency, distribution, mobility, and coordination C. Varela and G. Agha, “Programming dynamically reconfigurable open systems with SALSA”, ACM SIGPLAN Notices, OOPSLA 2001, 36(12), pp 20-34. C. Varela

Agha, Mason, Smith & Talcott Extend a functional language (λ-calculus + ifs and pairs) with actor primitives. Define an operational semantics for actor configurations. Study various notions of equivalence of actor expressions and configurations. Assume fairness: Guaranteed message delivery. Individual actor progress. C. Varela

Open Distributed Systems Addition of new components Replacement of existing components Changes in interconnections C. Varela

Synchronous vs. Asynchronous Communication The π-calculus (and other process algebras such as CCS, CSP) take synchronous communication as a primitive. The actor model assumes asynchronous communication is the most primitive interaction mechanism. C. Varela

Communication Medium In the π-calculus, channels are explicitly modeled. Multiple processes can share a channel, potentially causing interference. In the actor model, the communication medium is not explicit. Actors (active objects) are first-class, history-sensitive entities with an explicit identity used for communication. C. Varela

Fairness The actor model theory assumes fair computations: Message delivery is guaranteed. Individual actor computations are guaranteed to progress. Fairness is very useful for reasoning about equivalences of actor programs but can be hard/expensive to guarantee; in particular when distribution and failures are considered. C. Varela

λ-Calculus as a Model for Sequential Computation Syntax e ::= v value | λv.e functional abstraction | ( e e ) application Example of beta-reduction: ( λx.x2 2 ) x2{2/x} λx.x2 2 22 C. Varela

λ-Calculus extended with pairs pr(x,y) returns a pair containing x & y ispr(x) returns t if x is a pair; f otherwise 1st(pr(x,y)) = x returns the first value of a pair 2nd(pr(x,y)) = y returns the second value of a pair C. Varela

Actor Primitives send(a,v) new(b) ready(b) Sends value v to actor a. Creates a new actor with behavior b (a λ-calculus abstraction) and returns the identity/name of the newly created actor. ready(b) Becomes ready to receive a new message with behavior b. C. Varela

AMST Actor Language Examples b5 = rec(λy. λx.seq(send(x,5),ready(y))) receives an actor name x and sends the number 5 to that actor, then it becomes ready to process new messages with the same behavior y. Sample usage: send(new(b5), a) A sink, an actor that disregards all messages: sink = rec(λb. λm.ready(b)) C. Varela

Reference Cell Using the cell: cell = rec(λb.λc.λm. if ( get?(m), seq( send(cust(m), c), ready(b(c))) if ( set?(m), ready(b(contents(m))), ready(b(c))))) Using the cell: let a = new(cell(0)) in seq( send(a, mkset(7)), send(a, mkset(2)), send(a, mkget(c))) C. Varela

Join Continuations Consider: treeprod = rec(λf.λtree. if(isnat(tree), f(left(tree))*f(right(tree)))) which multiplies all leaves of a tree, which are numbers. You can do the “left” and “right” computations concurrently. C. Varela

Tree Product Behavior Btreeprod = rec(λb.λm. seq(if(isnat(tree(m)), send(cust(m),tree(m)), let newcust=new(Bjoincont(cust(m))), lp = new(Btreeprod), rp = new(Btreeprod) in seq(send(lp, pr(left(tree(m)),newcust)), send(rp, pr(right(tree(m)),newcust)))), ready(b))) C. Varela

Tree Product (continued) Bjoincont = λcust.λfirstnum.ready(λnum. seq(send(cust,firstnum*num), ready(sink))) C. Varela

Sample Execution f(tree,cust) f(left(tree),JC) f(right(tree),JC) JC (b) C. Varela

Sample Execution f(left(tree),JC) JC’ JC firstnum cust cust cust (d) C. Varela

Sample Execution num Cust firstnum JC firstnum * num Cust Cust (e) (f) C. Varela

Operational Semantics for AMST Actor Language Operational semantics of actor model as a labeled transition relationship between actor configurations. Actor configurations model open system components: Set of individually named actors Messages “en-route” C. Varela

Actor Configurations k = α || µ α is a function mapping actor names (represented as free variables) to actor states. µ is a multi-set of messages “en-route.” C. Varela

Syntactic restrictions on configurations Given A = Dom(α): If a in A, then fv(α(a)) is a subset of A. If <a <= v> in µ, then {a} U fv(v) is a subset of A. C. Varela

Reduction contexts and redexes Consider the expression: e = send(new(b5), a) The redex r represents the next sub-expression to evaluate in a left-first call-by-value evaluation strategy. The reduction context R (or continuation) is represented as the surrounding expression with a hole replacing the redex. send(new(b5), a) = send(☐,a) new(b5) e = R r where R = send(☐,a) r = new(b5) C. Varela

Labeled Transition Relation C. Varela

Exercises Write get? cust set? contents mkset mkget to complete the reference cell example in the AMST actor language. Modify the cell behavior to notify a customer when the cell value has been updated. PDCS Exercise 4.6.6 (page 77). PDCS Exercise 4.6.7 (page 78). C. Varela