Chair of Software Engineering Piotr Nienaltowski, 23.05.2006, 30.05.2006 Concurrent Object-Oriented Programming Bertrand Meyer, Piotr Nienaltowski.

Slides:



Advertisements
Similar presentations
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Advertisements

SCOOP: Simple Concurrent Object-Oriented Programming Extend the pure, strongly typed, object-oriented language Eiffel with a general and powerful concurrency.
Eiffel: Analysis, Design and Programming Bertrand Meyer (Nadia Polikarpova) Chair of Software Engineering.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 10: Advanced Object-Oriented Mechanisms (based on.
Programming Languages and Paradigms
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
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 7: References and Assignment.
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.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
“THREADS CANNOT BE IMPLEMENTED AS A LIBRARY” HANS-J. BOEHM, HP LABS Presented by Seema Saijpaul CS-510.
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 OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Chair of Software Engineering Piotr Nienaltowski, , Concurrent Object-Oriented Programming Bertrand Meyer, Piotr Nienaltowski.
1 Advanced Material The following slides contain advanced material and are optional.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
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.
SCOOP: Simple Concurrent Object-Oriented Programming Piotr Nienaltowski, Volkan Arslan, Bertrand Meyer presented by: Mark Schall.
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 Avoid a void Bertrand Meyer ©Bertrand Meyer, 2008.
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 ATOT - Lecture 23, 23 June Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 6: Genericity.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
CS510 Concurrent Systems Class 5 Threads Cannot Be Implemented As a Library.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 6:Computational Model (based on work with Piotr Nienaltowski)
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 2: an overview of SCOOP.
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.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
10 Conversion. Let’s start with conformance Conformance determines when a type may be used in lieu of another. Conformance relies on inheritance. The.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
More About Classes Ranga Rodrigo. Information hiding. Copying objects.
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.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 02] Introduction to.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Shared Memory Consistency Models. SMP systems support shared memory abstraction: all processors see the whole memory and can perform memory operations.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Ceg860 (Prasad)L17IT1 Inheritance Techniques Subcontracting Anchored Types.
DBC NOTES. Design By Contract l A contract carries mutual obligations and benefits. l The client should only call a routine when the routine’s pre-condition.
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
CLASSES AND OBJECTS Chapter 3 : constructor, Separate files, validating data.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Design by Contract Jim Fawcett CSE784 – Software Studio
SCOOPLI for .NET: a library for concurrent object-oriented programming
Threads and Memory Models Hal Perkins Autumn 2011
Introduction to Classes and Objects
Threads and Memory Models Hal Perkins Autumn 2009
Presentation transcript:

Chair of Software Engineering Piotr Nienaltowski, , Concurrent Object-Oriented Programming Bertrand Meyer, Piotr Nienaltowski

Chair of Software Engineering Piotr Nienaltowski, , Lecture 8 - 9: Traitors, validity rules, type system

Chair of Software Engineering Piotr Nienaltowski, , Outline  Traitors  Validity rules – first attempt  Type system for SCOOP  Handling false traitors

Chair of Software Engineering Piotr Nienaltowski, , Refresher: computational model  Software system is composed of several processors  Processors are sequential; concurrency is achieved through their interplay  Separate entity denotes a potentially separate object  Calls to non-separate objects are synchronous  Calls to separate objects are asynchronous

Chair of Software Engineering Piotr Nienaltowski, , Refresher: synchronisation  Mutual exclusion  Locking through argument passing  Routine body is critical section  Condition synchronisation  wait-conditions  Re-synchronisation of client and supplier:  wait-by-necessity  Lock passing through argument passing

Chair of Software Engineering Piotr Nienaltowski, , Refresher: separate call rule A routine call with separate arguments will execute when all corresponding objects are available and wait-conditions are satisfied and hold the objects exclusively for the duration of the routine

Chair of Software Engineering Piotr Nienaltowski, , What SCOOP can do for us  Beat enemy number one in concurrent world, i.e. atomicity violations  Data races  Illegal interleavings of calls  Data races cannot occur in SCOOP.  Why? See computational model...  Separate call rule does not protect us from bad interleaving of calls!  How can this happen?

Chair of Software Engineering Piotr Nienaltowski, , Traitors here… -- supplier class X feature a: A end Is this call valid? And this one? TRAITOR! -- in class C (client) my_x: separate X a: A … r (x: separate X) is do a := x.a end … r (my_x) a.f

Chair of Software Engineering Piotr Nienaltowski, , Traitors there… -- in class C (client) my_x: separate X a: A … r (x: separate X) is do x.f (a) end … r (my_x) -- supplier class X feature f (a: A) is do a.f end Is this call valid? And this one? TRAITOR!

Chair of Software Engineering Piotr Nienaltowski, , Consistency rules – first attempt  Original model defines four consistency rules that eliminate traitors  See OOSC2 chapter 30 for details  Written in English  Easy to understand by programmers  Are they sound? Are they complete?

Chair of Software Engineering Piotr Nienaltowski, , SCOOP rules – first attempt Separateness consistency rule (1) If the source of an attachment (assignment instruction or argument passing) is separate, its target entity must be separate too. r (buffer: separate BUFFER [X]; x: X ) is local b1: separate BUFFER [X] b2: BUFFER [X] x2: separate X do b1 := buffer-- valid b2 := b1-- invalid r (b1, x2) -- invalid end

Chair of Software Engineering Piotr Nienaltowski, , SCOOP rules – first attempt Separateness consistency rule (2) If an actual argument of a separate call is of a reference type, the corresponding formal argument must be declared as separate. store (buffer: separate BUFFER [X]; x: X ) is do buffer.put (x) end -- in class BUFFER [G] put (element: separate G) is...

Chair of Software Engineering Piotr Nienaltowski, , SCOOP rules – first attempt Separateness consistency rule (3) If the source of an attachment is the result of a separate call to a function returning a reference type, the target must be declared as separate. consume_element (buffer: separate BUFFER [X]) is local element: separate X do element := buffer.item... end -- in class BUFFER [G] item: G is...

Chair of Software Engineering Piotr Nienaltowski, , SCOOP rules – first attempt Separateness consistency rule (4) If an actual argument of a separate call is of an expanded type, its base class may not include, directly or indirectly, any non-separate attribute of a reference type. store (buffer: separate BUFFER [X]; x: X ) is do buffer.put (x)-- X must be “fully expanded” end -- in class BUFFER [G] put (element: G) is-- G is not declared as separate anymore...

Chair of Software Engineering Piotr Nienaltowski, , Problem 1: unsoundness x: X-- X is expanded, see below. consume_element (buffer: separate BUFFER [X]) is local s: STRING do x := buffer.item s := x.f.out-- Valid: call on expanded object. s := x.g.out-- Valid! call on separate reference. end expanded class X feature g: STRING f: INTEGER is... end traitor!!!

Chair of Software Engineering Piotr Nienaltowski, , Problem 2: limitations my_x: X-- X is expanded, see below. my_y: separate Y... my_y.r (my_x)-- Invalid because my_x is not fully expanded. expanded class X feature g: STRING f: INTEGER is... end -- in class Y r (x: X) is do... end

Chair of Software Engineering Piotr Nienaltowski, , Problem 3: more limitations class STRING feature... append alias infix “+” (other: like Current) is do... end -- in class X r (l: separate LIST [STRING]) is do l.put (l.item (1) + l.item (2)) end Invalid!!! But it should be allowed!

Chair of Software Engineering Piotr Nienaltowski, , Problem 4: even more limitations r (l: separate LIST [STRING]) is local s: separate STRING do s := l.item (1) l.put (s) end Invalid!!! But it should be allowed!

Chair of Software Engineering Piotr Nienaltowski, , Let’s make it better!  SCOOP rules  prevent almost all traitors, +  are easy to understand by humans, +  cannot be directly used by compilers, -  not sound, -  too restrictive, -  no support for agents. -  Can we do better?  Refine and formalise the rules!

Chair of Software Engineering Piotr Nienaltowski, , The question for today How do you know whether assignment x := y -- x and y are declared as -- x: CLASS_X; y: CLASS_Y and argument passing r (x) -- r is declared as r (an_x: SOME_CLASS) are valid? Type system tells you that!

Chair of Software Engineering Piotr Nienaltowski, , Type system for SCOOP  Prevents all traitors  static (compile-time) checks  Simplifies, refines and formalises SCOOP rules  Integrates expanded types and agents with SCOOP  More about it in lecture 10  Tool for reasoning about concurrent programs  May serve as basis for future extensions, e.g. for deadlock prevention schemes

Chair of Software Engineering Piotr Nienaltowski, , Three components of a type  Class type C  Processor tag   { ●, T, ,, }  Attached/detachable   {!, ?}  x :: ( , , C) Current processor x: X Some processor (top) x: separate X No processor (bottom) Void

Chair of Software Engineering Piotr Nienaltowski, , Examples x: X-- x :: (!, ●, X) y: separate Y-- y :: (!, T, Y) z: ? separate Z-- z :: (?, T, Z)  Expanded types are attached and non-separate i: INTEGER-- i :: (!, ●, INTEGER)  Void is detachable-- Void :: (?, , NONE)  Current is attached and non-separate -- Current :: (!, ●, C Current )

Chair of Software Engineering Piotr Nienaltowski, , Subtyping rules  Since you don’t like Greek letters, I’ll keep it informal  TT 2 ≤ TT 1 means “TT 2 is a subtype of TT 1 ”  Conformance on class types like in Eiffel, essentially based on inheritance D ≤ Eiffel C ( , , D) ≤ ( , , C)  Attached ≤ detachable (!, , C) ≤ (?, , C)  Any processor tag ≤ T ( , , C) ≤ ( , T, C)  In particular, non-separate ≤ T ( , ●, C) ≤ ( , T, C)   ≤ any processor tag ( , , C) ≤ ( , , C)

Chair of Software Engineering Piotr Nienaltowski, , So how does it help us?  We can rely on standard type rules  Enriched types give us additional guarantees  Assignment rule: source conforms to target  |- x :: TT x,  |- e :: TT e,  |- TT e ≤ TT x [Assign]  |- x := e  No need for special validity rules for separate

Chair of Software Engineering Piotr Nienaltowski, , Is it always that simple?  Rules for feature calls are more complex  “Targettability” of target taken into account  Is target attached?  Is target’s handler accessible to client’s handler?  Type of formal arguments depends on type of target

Chair of Software Engineering Piotr Nienaltowski, , Unified rules for call validity  Informally, entity x may be used as target of a feature call in the context of routine r if and only if x is attached and processor that executes r has exclusive access to x ’s processor. Definition (Targettable entity) Entity x is targettable, i.e. it may be used as target of a feature call in the context of routine r, if and only if x is of attached type, it is declared with processor tag  and some attached formal argument of r has processor tag .

Chair of Software Engineering Piotr Nienaltowski, , Feature call rules Definition (Valid call) Call x.f (a) appearing in the context of routine r in class C is valid iff the following conditions hold:  x is targettable.  x ’s base class has feature f exported to C, and actual arguments a conform in number and type to formal arguments of f.  Type combinators necessary to calculate relative type  formal arguments   result *

Chair of Software Engineering Piotr Nienaltowski, , Type combinator * (result type) (, , C) * (, , D) = (,, D)   ● T ● ● TT TTTT TT

Chair of Software Engineering Piotr Nienaltowski, , Type combinator  (formals) (, , C)  (, , D) = (,, D)   ● T ● ● T  T  T  T 

Chair of Software Engineering Piotr Nienaltowski, , Expanded types  Both * and  preserve expanded types (, , C) * (!, ●, INTEGER) = (!, ●, INTEGER) (, , C)  (!, ●, BOOLEAN) = (!, ●, BOOLEAN) my_x: X-- my_x :: (!, ●, X) expanded class X my_y: separate Y -- my_y :: (!, T, Y) feature... g: STRING my_y.r (my_x) f: INTEGER is (!, ●, X) ≤ (!, T, Y)  (!, ●, X) end -- so call is valid

Chair of Software Engineering Piotr Nienaltowski, , Expanded types: deep_import  Expanded objects are non-separate  How to prevent traitors?  Implicit deep_import operation  Just like copy but it clones (recursively) all non-separate attributes

Chair of Software Engineering Piotr Nienaltowski, , Recall: traitors here supplier class X feature a: A end TRAITOR! -- in class C (client) my_x: separate X a: A … r (x: separate X) is do a := x.a end … r (my_x) a.f

Chair of Software Engineering Piotr Nienaltowski, , Type system eliminates them -- supplier class X feature a: A -- a:: (!, ●, A) end -- in class C (client) my_x: separate X -- my_x :: (!, T, X) a: A-- a :: (!, ●, X) … r (x: separate X) is -- x :: (!, T, X) do a := x.a-- x.a :: (!, T, X) * (!, ●, A) = (!, T, A) -- (!, T, A) ≤ (!, ●, A) -- therefore assignment is invalid end … r (my_x)-- (!, T, X) ≤ (!, ●, C)  (!, T, X), so call is valid a.f

Chair of Software Engineering Piotr Nienaltowski, , Recall: traitors there… -- in class C (client) my_x: separate X a: A … r (x: separate X) is do x.f (a) end … r (my_x) -- supplier class X feature f (a: A) is do a.f end TRAITOR!

Chair of Software Engineering Piotr Nienaltowski, , Type system eliminates them -- in class C (client) my_x: separate X -- my_x :: (!, T, X) a: A -- a:: (!, ●, A) … r (x: separate X) is -- x :: (!, T, X) do x.f (a) -- (!, ●, A) ≤ (!, T, X)  (!, ●, A) -- (!, ●, A) ≤ (!, , A) -- therefore call is invalid end … r (my_x) (!, T, X) ≤ (!, ●, C)  (!, T, X), so call is valid -- supplier class X feature f (a: A) is -- a:: (!, ●, A) do a.f end

Chair of Software Engineering Piotr Nienaltowski, , Explicit processor tags p: HANDLER-- Tag declaration x: separate X-- x :: (!,, X) y: separate Y-- y :: (!,, Y) z: separate Z-- z :: (!, T, Z)  Attachment -- Assume that Y and Z inherit from X x := y -- Valid because (!,, Y) ≤ (!,, X) y := z-- Invalid because (!, T, Z) ≤ (!,, Y)  Object creation create x -- Fresh processor is created to handle x. create y -- No new processors created; y is put -- on x’s processor.

Chair of Software Engineering Piotr Nienaltowski, , Implicit processor tags  Declared using “feature” handler on a read-only attached entity (formal argument, Current) x: separate X -- x is handled by roe’s handler.  Attachment, object creation r (list: separate LIST [X]) local s1, s2: separate STRING -- s1 :: (!,, STRING), s2 alike do s1 := list.item (1) s2 := list.item (2) list.extend (s1 + s2) -- Valid create s1.make_empty -- s1 created on list’s processor list.extend (s1) -- Valid end

Chair of Software Engineering Piotr Nienaltowski, , False traitors spouse friend spouse friend spouse friend processor 1 processor 2 wife hubby Urs meet_friend (person: separate PERSON) is local a_friend: PERSON do a_friend := person.friend-- Invalid assignment. visit (a_friend) end

Chair of Software Engineering Piotr Nienaltowski, , meet_friend (person: separate PERSON) is local a_friend: PERSON do a_friend ?= person.friend-- Valid assignment attempt. if a_friend /= void then visit (a_friend) end end Handling false traitors spouse friend spouse friend spouse friend processor 1 processor 2 wife hubby Urs

Chair of Software Engineering Piotr Nienaltowski, , Assignment attempt  Like in Eiffel but also “downcasts” processor tags  “deep downcast” over expanded attributes  Eiffel standard has replaced ?= with object test if {a_friend: PERSON} person.friend then visit (a_friend) end

Chair of Software Engineering Piotr Nienaltowski, , That’s all, folks! Questions?