Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 2: an overview of SCOOP.

Slides:



Advertisements
Similar presentations
Design By Contract Using JMSAssert.
Advertisements

SCOOP: Simple Concurrent Object-Oriented Programming Extend the pure, strongly typed, object-oriented language Eiffel with a general and powerful concurrency.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 10: Advanced Object-Oriented Mechanisms (based on.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Exercise Session 1: Eiffel Introduction.
2 nd Microsoft Rotor Workshop, Pisa, April 23-25, SCOOPLI for.NET: a library for concurrent object-oriented programming Volkan Arslan, Piotr Nienaltowski.
SCOOP on.NET Volkan Arslan Chair of Software Engineering ETH Zurich, Switzerland
Chapter 6: Process Synchronization
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 3: Abstract Data Types.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 7: SCOOP Type System (based on work with Piotr Nienaltowski)
Chair of Software Engineering PPoPP 2003, , San Diego SCOOP it up! Piotr Nienaltowski Chair of Software Engineering, ETH Zurich, Switzerland.
1 Concurrency Specification. 2 Outline 4 Issues in concurrent systems 4 Programming language support for concurrency 4 Concurrency analysis - A specification.
1 Software Architecture Bertrand Meyer ETH Zurich, March-May 2009 Lecture 15: Designing for concurrency & real-time.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC Lecture 20 - Concurrency Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Piotr Nienaltowski, SCOOP Simple Concurrent Object-Oriented Programming.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 2: Dealing with Objects I.
Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Piotr Nienaltowski, , Concurrent Object-Oriented Programming Bertrand Meyer, Piotr Nienaltowski.
Chair of Software Engineering Piotr Nienaltowski, , Concurrent Object-Oriented Programming Bertrand Meyer, Piotr Nienaltowski.
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
Chair of Software Engineering SCOOP for ROTOR Bertrand Meyer Capstone (ROTOR final workshop), 2005 © Bertrand Meyer, 2005.
Chair of Software Engineering ATOT - Lecture 26, 30 June Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
Chair of Software Engineering OOSC - Lecture 4 1 Object-Oriented Software Construction Bertrand Meyer.
SCOOP: Simple Concurrent Object-Oriented Programming Piotr Nienaltowski, Volkan Arslan, Bertrand Meyer presented by: Mark Schall.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Lecture 21 1 Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering ATOT - Lecture 25, 30 June Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 9: Contracts and Inheritance (based on work with.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 6: Genericity.
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 6:Computational Model (based on work with Piotr Nienaltowski)
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chair of Software EngineeringPiotr Nienaltowski, 2 nd SCOOP workshop, SCOOP update and proposed extensions Piotr Nienaltowski.
Chair of Software Engineering ATOT - Lecture 7, 23 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software EngineeringOOSC – Summer Semester 2005 Object-Oriented Software Construction Bertrand Meyer Lecture 19: SCOOP Simple Concurrent Object-Oriented.
Chair of Software Engineering ATOT - Lecture 22, 18 June Advanced Topics in Object Technology Bertrand Meyer.
Advances in Language Design
What is Concurrent Programming? Maram Bani Younes.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Operating Systems Lecture 2 Processes and Threads Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
ABSTRACT The real world is concurrent. Several things may happen at the same time. Computer systems must increasingly contend with concurrent applications.
Contracts for Concurrency - Contracts & Inheritance Aryabrata Basu University of Georgia.
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
Denis Caromel1 Institut universitaire de France (IUF) INRIA Sophia-Antipolis – CNRS – I3S – Université de Nice Luis Mateu DCC – Universidad de Chile Eric.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Adding Concurrency to a Programming Language Peter A. Buhr and Glen Ditchfield USENIX C++ Technical Conference, Portland, Oregon, U. S. A., August 1992.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Advanced Operating Systems CIS 720
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
SCOOPLI for .NET: a library for concurrent object-oriented programming
Simple Concurrent Object-Oriented Programming
Chapter 4: Threads.
What is Concurrent Programming?
What is Concurrent Programming?
Generics, Lambdas and Reflection
Presentation transcript:

Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 2: an overview of SCOOP

2 2 put (b : [G ] ; v : G ) -- Store v into b. require not b. is_full do … ensure not b. is_empty end QUEUE BUFFER my_queue : [T ] … if not my_queue. is_full then put (my_queue, t ) end BUFFER QUEUE put item, remove

3 The issue Concurrency everywhere:  Multithreading  Multitasking  Networking, Web services, Internet Can we bring concurrent programming to the same level of abstraction and convenience as sequential programming?  Multicore

4 Previous advances in programming “Structured programming” “Object technology” Use higher-level abstractions Helps avoid bugs Transfers tasks to implementation Lets you do stuff you couldn’t before NO Has well-understood math basis Doesn’t require understanding that basis Removes restrictions NO Adds restrictions Permits less operational reasoning

5 Then and now Sequential programming: Used to be messy Still hard but key improvements:  Structured programming  Data abstraction & object technology  Design by Contract  Genericity, multiple inheritance  Architectural techniques Concurrent programming: Used to be messy Example: threading models in most popular approaches Development level: sixties/seventies Only understandable through operational reasoning Still messy

6 The chasm Theoretical models, process calculi… Elegant theoretical basis, but  Little connection with practice (some exceptions, e.g. BPEL)  Handle concurrency aspects only Practice of concurrent & multithreaded programming  Little influenced by above  Low-level, e.g. semaphores  Poorly connected with rest of programming model

7 Wrong (in my opinion) assumptions “Objects are naturally concurrent ” (Milner)  Many attempts, often based on “Active objects” (a self-contradictory notion)  Lead to artificial issue of “Inheritance anomaly” “Concurrency is the basic scheme, sequential programming a special case ” (many)  Correct in principle, but in practice we understand sequential best

8 SCOOP mechanism Simple Concurrent Object-Oriented Programming Evolved through last decade; CACM (1993) and chap. 32 of Object-Oriented Software Construction, 2 nd edition, 1997 Implemented at ETH, ongoing integration into EiffelStudio Current state is described in Piotr Nienaltowski’s 2007 ETH PhD dissertation

9 Dining philosophers class PHILOSOPHER inherit PROCESS rename setup as getup redefine step end feature {BUTLER} step do think ; eat (left, right) end eat (l, r : separate FORK) -- Eat, having grabbed l and r. do … end end

10 Typical traditional code

11 Object-oriented computation To perform a computation is  To apply certain actions  To certain objects  Using certain processors Processor Actions Objects

12 What makes an application concurrent? Processor: Thread of control supporting sequential execution of instructions on one or more objects Can be implemented as:  Computer CPU  Process  Thread  AppDomain (.NET) … Will be mapped to computational resources Processor Actions Objects

13 put (b : [G ] ; v : G ) -- Store v into b. require not b. is_full do … ensure not b. is_empty end BUFFER my_queue : [T ] … if not my_queue. is_full then put (my_queue, t ) end BUFFER put item, remove

14 Reasoning about objects: sequential {INV and Pre r } body r {INV and Post r } ___________________________________ {Pre r ’ } x. r (a) {Post r ’ } Priming represents actual-formal argument substitution Only n proofs if n exported routines!

15 In a concurrent context Only n proofs if n exported routines? {INV and Pre r } body r {INV and Post r } ___________________________________ {Pre r ’} x. r (a) {Post r ’} Client 1 r1 Client 2 r2 Client 3 r3 No overlapping!

16 SCOOP rules  One processor per object: “handler”  At most one feature (operation) active on an object at any time

17 Feature call: sequential x. r (a) Processor Client Supplier previous x. r (a) next r (x : A) do … end

18 Feature call: asynchronous Client Supplier previous x. r (a) next r (x : A) do … end Client’s handler Supplier’s handler

19 The fundamental difference To wait or not to wait:  If same processor, synchronous  If different processor, asynchronous Difference must be captured by syntax:  x: X  x: separate X -- potentially different processor Fundamental semantic rule: x. r (a) waits for non- separate x, doesn’t wait for separate x.

20 Consistency rules: avoiding traitors nonsep: T sep: separate T nonsep := sep nonsep. p (a) Traitor!

21 Trusting what you read my_stack: separate STACK [T] … my_stack. push (a) … Instructions not affecting the stack… y := my_stack. top

22 Access control policy Require target of separate call to be formal argument of enclosing routine: push (stack : separate STACK [T]; value: T) -- Add value on top of stack. do stack. push (value) end

23 Access control policy Target of a separate call must be formal argument of enclosing routine: put (buffer : separate BUFFER [T ]; value : T) -- Store value into buffer. do buffer. put (value) end To use separate object: my_buffer : separate BUFFER [INTEGER ] create my_buffer put (my_buffer, 10)

24 Separate argument rule The target of a separate call must be an argument of the enclosing routine Separate call: x.f (...) where x is separate

25 Wait rule A routine call with separate arguments will execute when all corresponding processors are available and hold them exclusively for the duration of the routine

26 Dining philosophers class PHILOSOPHER inherit PROCESS rename setup as getup redefine step end feature {BUTLER} step do think ; eat (left, right) end eat (l, r : separate FORK) -- Eat, having grabbed l and r. do … end end

27 Resynchronization No explicit mechanism needed for client to resynchronize with supplier after separate call. The client will wait only when it needs to: x.fx.f x. g (a) y.fy.f … value := x. some_query Lazy wait (Denis Caromel, wait by necessity) Wait here!

28 put (buf : BUFFER [INTEGER ] ; v : INTEGER) -- Store v into buffer. require not buf. is_full v > 0 do buf. put (v) ensure not buf. is_empty end... put (my_buffer, 10 ) Contracts

29 put (b : [G ] ; v : G ) -- Store v into b. require not b. is_full do … ensure not b. is_empty end BUFFER my_queue : [T ] … if not my_queue. is_full then put (my_queue, t ) end BUFFER put item, remove

30 put (buf : BUFFER [INTEGER ] ; v : INTEGER) -- Store v into buffer. require not buf. is_full v > 0 do buf. put (v) ensure not buf. is_empty end... put (my_buffer, 10 ) Contracts Precondition becomes wait condition

31 Full synchronization rule A call with separate arguments waits until:  The corresponding objects are all available  Preconditions hold x.f (a) where a is separate

32 Which semantics applies? put (buf : separate BUFFER [INTEGER]; i : INTEGER) require not buf. is_full i > 0 do buf. put (i) end Wait condition Correctness condition my_buffer : separate BUFFER [INTEGER] put (my_buffer, 10)

33 Generalized semantics of preconditions  Sequentiality is a special case of concurrency.  Wait semantics always applies.  Wait semantics boils down to correctness semantics for non-separate preconditions.  Smart compiler can detect some cases  Other cases detected at run time Distinction between controlled and uncontrolled rather than separate and non-separate.

34 What about postconditions? Should we wait for zurich. is_ready? spawn_two_activities (loc1, loc2: separate LOCATION) do loc1. do_job loc2. do_job ensure loc1. is_ready loc2. is_ready end spawn_two_activities (zurich, palo_alto) do_local_stuff get_result (zurich) zurich, palaiseau : separate LOCATION

35 Reasoning about objects: sequential {INV and Pre r } body r {INV and Post r } ___________________________________ {Pre r ’ } x. r (a) {Post r ’ } Only n proofs if n exported routines!

36 Refined proof rule (partial correctness) {INV  Pre r (x)} body r {INV  Post r (x)} {Pre r (a cont )} e. r (a) {Post r (a cont )} Hoare-style sequential reasoning Controlled expressions (known statically as part of the type system) are:  Attached (statically known to be non-void)  Handled by processor locked in current context

37 Elevator example architecture For maximal concurrency, all objects are separate Inheritance Client

38 Other aspects What if a separate call, e.g. in r (a : separate T) do a. f a. g a. h end causes an exception?

39 Implementation: two-level architecture Adaptable to many environments Currently implemented for native Windows (using POSIX threads) and.NET SCOOPLI platform-independent POSIX threads.NET Threading …

40 Status  All of SCOOP except exceptions and duels implemented  Preprocessor and library available for download  Numerous examples available for download se.ethz.ch/research/scoop.html

41 Current developments Implementation: integrating into EiffelStudio Performance evaluation Theory:  Deadlock prevention and detection  Less restrictive model (see STM)  Transactions  Full-fledged semantics  Distributed SCOOP, Web Services

42 Why SCOOP?  Simple (one new keyword) yet powerful  Easier and safer than common concurrent techniques, e.g. Java Threads  Full concurrency support  Full use of O-O and Design by Contract  Retains ordinary thought patterns, modeling power of O-O  Supports wide range of platforms and concurrency architectures  Programmers need to sleep better!