C. Varela1 Actors (PDCS 4) AMST actor language syntax, semantics, join continuations Carlos Varela Rennselaer Polytechnic Institute April 16, 2015.

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)
Software Connectors Software Architecture. Importance of Connectors Complex, distributed, multilingual, modern software system functionality and managing.
Introduction CSCI 444/544 Operating Systems Fall 2008.
IBM WebSphere survey Kristian Bisgaard Lassen. University of AarhusIBM WebSphere survey2 Tools  WebSphere Application Server Portal Studio Business Integration.
Concurrency in Ada What concurrency is all about Relation to operating systems Language facilities vs library packages POSIX threads Ada concurrency Real.
1: Operating Systems Overview
Concurrency CS 510: Programming Languages David Walker.
Lecture 19 Distributed Programming (Ch. 10) Other message-passing programming models  Channels vs mailboxes  Synchronous vs asynchronous.
Review of “Embedded Software” by E.A. Lee Katherine Barrow Vladimir Jakobac.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
An introduction to F# (part 2) Bogdan Brinzarea-Iamandi Banca Romaneasca 25 February 2010.
3.5 Interprocess Communication
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
1 Programming systems for distributed applications Seif Haridi KTH/SICS.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
CS603 Communication Mechanisms 14 January Types of Communication Shared Memory Message Passing Stream-oriented Communications Remote Procedure Call.
Processes Part I Processes & Threads* *Referred to slides by Dr. Sanjeev Setia at George Mason University Chapter 3.
Process Description and Control. Process concepts n Definitions – replaces task, job – program in execution – entity that can be assigned to and executed.
1 Testing Concurrent Programs Why Test?  Eliminate bugs?  Software Engineering vs Computer Science perspectives What properties are we testing for? 
Computer System Architectures Computer System Software
9/10/2015CS2104, Lecture 81 Programming Language Concepts, COSC Lecture 8 (Multiple) Threads Semantics.
(C) 2009 J. M. Garrido1 Object Oriented Simulation with Java.
Experience with Processes and Monitors in Mesa
Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server.
SALSA: Language and Architecture for Widely Distributed Actor Systems. Carlos Varela, Abe Stephens, Department of.
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.
- 1 - Embedded Systems - SDL Some general properties of languages 1. Synchronous vs. asynchronous languages Description of several processes in many languages.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
CS 152: Programming Language Paradigms May 7 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
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.
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
Programming Paradigms for Concurrency Pavol Cerny Vasu Singh Thomas Wies Part III – Message Passing Concurrency.
The Complexity of Distributed Algorithms. Common measures Space complexity How much space is needed per process to run an algorithm? (measured in terms.
Actors: a model of concurrent computation in Distributed Systems Amin Saremi Hamid Mohamadi.
Using a simple Rendez-Vous mechanism in Java
ICS 313: Programming Language Theory Chapter 13: Concurrency.
S. Haridi and P. Van Roy1 Concurrency and State Seif Haridi KTH Peter Van Roy UCL.
Computing Simulation in Orders Based Transparent Parallelizing Pavlenko Vitaliy Danilovich, Odessa National Polytechnic University Burdeinyi Viktor Viktorovych,
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,
Several sets of slides by Prof. Jennifer Welch will be used in this course. The slides are mostly identical to her slides, with some minor changes. Set.
C. Varela1 Distributed systems abstractions (PDCS 9, CPE 6*) Carlos Varela Rennselaer Polytechnic Institute October 20, 2015 * Concurrent Programming in.
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.
What’s Ahead for Embedded Software? (Wed) Gilsoo Kim
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.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
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.
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Distributed systems abstractions (PDCS 9, CPE 6*)
Rennselaer Polytechnic Institute
Carlos Varela Rennselaer Polytechnic Institute October 6, 2017
Distributed (Systems) Programming Universal Actors, SALSA, World-Wide Computer Carlos Varela RPI C. Varela.
Concurrency control abstractions (PDCS 9, CPE 5*)
Declarative Concurrency (CTM 4)
Background and Motivation
Carlos Varela Rennselaer Polytechnic Institute October 4, 2016
Introduction to Programming Concepts (VRH )
Concurrent Programming Actors, SALSA, Coordination Abstractions
Presentation transcript:

C. Varela1 Actors (PDCS 4) AMST actor language syntax, semantics, join continuations Carlos Varela Rennselaer Polytechnic Institute April 16, 2015

C. Varela2 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. Varela3 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. Varela4 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. Varela5 Actors/SALSA Actor Model –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, Agha, Mason, Smith and Talcott, “A Foundation for Actor Computation”, J. of Functional Programming, 7, 1-72, 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

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

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

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. Varela8

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. Varela9

Fairness The actor model theory assumes fair computations: 1.Message delivery is guaranteed. 2.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. Varela10

λ-Calculus as a Model for Sequential Computation Syntax e ::= vvalue | λv.efunctional abstraction | ( e e )application Example of beta-reduction: ( λx.x 2 2 ) x 2 {2/x} C. Varela11 λx.x 2 2 2

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

Actor Primitives send(a,v) –Sends value v to actor a. new(b) –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. Varela13

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. Varela14

Reference 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. Varela15

Join Continuations Consider: treeprod = rec(λf.λtree. if(isnat(tree), 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. Varela16

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

Tree Product (continued) B joincont = λcust.ready( λfirstnum.ready(λnum. seq(send(cust,firstnum*num), ready(sink)))) C. Varela18

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

Sample Execution C. Varela20 cust JC ’ JC cust JC firstnum (c) JC ' JC firstnum JC ' cust firstnum JC (d) JC ’ f(left(tree),JC)

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

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. Varela22

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. Varela23

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

Labeled Transition Relation C. Varela25

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