Chair of Software Engineering OOSC - Summer Semester 2004 1 Object-Oriented Software Construction Bertrand Meyer.

Slides:



Advertisements
Similar presentations
SCOOP: Simple Concurrent Object-Oriented Programming Extend the pure, strongly typed, object-oriented language Eiffel with a general and powerful concurrency.
Advertisements

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
Chair of Software Engineering The alias calculus Bertrand Meyer ITMO Software Engineering Seminar June 2011.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
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 OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 3: Abstract Data Types.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
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 Software Architecture Prof. Dr. Bertrand Meyer Lecture 6: Exception Handling.
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Design by Contract ™. 2 Design by Contract A discipline of analysis, design, implementation, management.
Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any.
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 ATOT - Lecture 10, 5 May Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland
Chair of Software Engineering ATOT - Lecture 25, 30 June Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 15: Exception handling.
-5- Exception handling What is an exception? “An abnormal event” Not a very precise definition Informally: something that you don’t want to happen.
Chair of Software Engineering Piotr Nienaltowski, , Concurrent Object-Oriented Programming Bertrand Meyer, Piotr Nienaltowski.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Software Testing and Quality Assurance
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 11: Design by Contract™
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering ATOT - Lecture 12, 12 May Advanced Topics in Object Technology 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.
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 Lecture 12: Design by Contract™
Chair of Software Engineering OOSC Summer Semester Object-Oriented Software Construction Bertrand Meyer.
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 OOSC - Summer Semester Object-Oriented Software Construction 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.
Chair of Software Engineering OOSC - Summer Semester 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 OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 6: Genericity.
Chair of Software Engineering OOSC - Summer Semester Bertrand Meyer Object-Oriented Software Construction Lecture 7: Inheritance.
Eiffel Language and Design by Contract Contract –An agreement between the client and the supplier Characteristics –Expects some benefits and is prepared.
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.
Contracts for Concurrency - Contracts & Inheritance Aryabrata Basu University of Georgia.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
CSC 480 Software Engineering Design by Contract. Detail Design Road Map Begin with architectural models  Class model: domain classes  Overall state.
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.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Semaphores Chapter 6. Semaphores are a simple, but successful and widely used, construct.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
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
Concurrency Specification
Design by contract Object-Oriented Software Construction by Bertrand Meyer, Prentice Hall The presence of a precondition or postcondition in a routine.
Design by contract Object-Oriented Software Construction by Bertrand Meyer, Prentice Hall The presence of a precondition or postcondition in a routine.
Semaphores Chapter 6.
Chapter 7: Synchronization Examples
Design by Contract – Exceptions
Presentation transcript:

Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer

Chair of Software Engineering OOSC - Summer Semester Lecture 25: Concurrent O-O principles

Chair of Software Engineering OOSC - Summer Semester class BOUNDED_QUEUE [G] feature put (x: G) is -- Add x to queue. require not is_full do … ensure not is_empty end remove: G is -- Delete oldest element from queue. require not is_empty do … ensure not is_full end Design by Contract

Chair of Software Engineering OOSC - Summer Semester The contract model (cont’d) invariant maxcount = capacity – 1 0 <= oldest oldest <= capacity 0 <= next next <= capacity abs (next – oldest) < capacity end 1 oldest capacity maxcount next

Chair of Software Engineering OOSC - Summer Semester The contract of a feature Client Supplier (Satisfy precondition:) Make sure queue not full. (Satisfy postcondition:) Insert x, making sure queue is not empty. Obligations (From postcondition:) Make queue not empty, x added. (From precondition:) Simpler processing thanks to assumption that queue not full. Benefits

Chair of Software Engineering OOSC - Summer Semester The correctness of a class  (1-n) For every exported routine r: {INV and pre r } do r {INV and post r }  (1-m) For every creation procedure cp: {pre cp } do cp {post cp and INV} a.f (…) a.g (…) a.f (…) create a.make (…) S1 S2 S3 S4

Chair of Software Engineering OOSC - Summer Semester Express messages?  An express message is a message that must be treated right away, interrupting any current routine call.  But: how do we preserve the consistency of objects (invariants)?  The model will support a restricted form of express messages, which does not conflict with provability.  Unit of granularity for mutual exclusion is routine call.  But: can be interrupted, causing an exception.

Chair of Software Engineering OOSC - Summer Semester Provability  Proof rule for routines: { INV  p } Body (r) { INV  q } p  Pre (r) q  Post (r) {p’ } Call (r) { q’ } p  Pre (r) q  Post (r)  In other words: to prove the validity of all calls, it suffices to prove (once!) the correctness of the body.

Chair of Software Engineering OOSC - Summer Semester What becomes of the contract model? q: BOUNDED_QUEUE [X] a: X... if not q.is_full then q.put (a) end Or: q.remove q.put (x)  But: this does not work for separate threads of control!  What do preconditions now mean?

Chair of Software Engineering OOSC - Summer Semester Reserving an object q: separate BOUNDED_QUEUE [X] a: X... a := q.item... Other instructions (not calling remove)... q.remove  How do we guarantee that item and remove apply to the same buffer element?  Proposed answer: Just use encapsulation. Argument passing serves as reservation. If object busy (processor not available), block object; processor will service other object if possible.

Chair of Software Engineering OOSC - Summer Semester Reserving an object (cont’d) class BUFFER_ACCESS [X] feature put (q: separate BOUNDED_QUEUE [G]; x: G) is -- Insert x into q, waiting if necessary -- until there is room. require not q.is_full do q.put (x) ensure not q.is_empty end

Chair of Software Engineering OOSC - Summer Semester Reserving an object (cont’d) remove (q: separate BOUNDED_QUEUE [G]) is -- Remove an element from q, waiting if -- necessary until there is such an element. require not q.is_empty do q.remove ensure not q.is_full end item (q: separate BOUNDED_QUEUE [G]): G is -- Oldest element not yet consumed... Left to reader... end

Chair of Software Engineering OOSC - Summer Semester Semantic rules  With the class as shown on the previous pages, the call put (q)  will block until:  q is available.  The precondition not q.is_full is true.  The new rule only affects:  Separate arguments.  Precondition clauses which include calls on separate targets (i.e. x.f with x separate).

Chair of Software Engineering OOSC - Summer Semester The original proof rule { INV  p } Body (r) { INV  q } p  Pre (r) q  Post (r) {p’ } Call (r) { q’ } p  Pre (r) q  Post (r)

Chair of Software Engineering OOSC - Summer Semester The new proof rule { INV  p } Body (r) { INV  q } p  Nonsep_Pre (r)q  Nonsep_Post (r) { p’ } Call (r) { q’ } p  Nonsep_Pre (r) q  Nonsep_Post (r)  Nonsep_pre (r): set of clauses in r’s precondition which do not involve any separate calls.  Similarly for Nonsep_post (r).

Chair of Software Engineering OOSC - Summer Semester Wait by necessity r (...; t: separate SOME_TYPE;...) is do... t.f (...) other_instructions end  When do we wait?

Chair of Software Engineering OOSC - Summer Semester Wait by necessity (cont’d)  For example: r (...; t: separate SOME_TYPE;...) is do... t.p (...) other_instruction_1... other_instruction_n k := t.some_value end  Wait on queries (calls to attributes and functions), not procedure calls. WAIT HERE

Chair of Software Engineering OOSC - Summer Semester Blocking semantics is not always appropriate f: FILE... if f /= Void and then f.readable then f.some_input_routine -- some_input_routine is any routine -- that reads data from the file; -- its precondition is readable. end

Chair of Software Engineering OOSC - Summer Semester Duels  Request immediate service: immediate_service  Accept immediate service: yield Exception in challenger Exception in holder; serve challenger. Challenger waits normal_serviceimmediate_service insist yield Challenger Holder

Chair of Software Engineering OOSC - Summer Semester Dining philosophers

Chair of Software Engineering OOSC - Summer Semester Dining philosophers (cont’d) separate class PHILOSOPHER inherit PROCESS rename setup as getup end create make feature {BUTLER} step is do think eat (left, right) end

Chair of Software Engineering OOSC - Summer Semester Dining philosophers (cont’d) feature {NONE} left, right: separate FORK -- The two required forks getup is -- Take any necessary initialization action. do... end think is -- Any appropriate action. do... end eat (l, r: separate FORK) is -- Eat, having grabbed l and r. do... end

Chair of Software Engineering OOSC - Summer Semester A binary tree class, non-parallel class BINARY_TREE [G] feature left, right: BINARY_TREE [G] nodes: INTEGER is -- Number of nodes in this tree do Result := node_count (left) + node_count (right) + 1 end feature {NONE} node_count (b: BINARY_TREE [G]): INTEGER is -- Number of nodes in b do if b /= Void then Result := b.nodes end

Chair of Software Engineering OOSC - Summer Semester A binary tree class: Parallel version separate class BINARY_TREE [G] feature left, right: BINARY_TREE [G] … Other features … nodes: INTEGER update_nodes is -- Update nodes to reflect number of nodes in this -- tree. do nodes := 1 compute_nodes (left) compute_nodes (right) adjust_nodes (left) adjust_nodes (right) end

Chair of Software Engineering OOSC - Summer Semester Parallel version (cont’d) feature {NONE} compute_nodes (b: BINARY_TREE [G]) is -- Update information about the number of nodes in b. do if b /= Void then b.update_nodes end adjust_nodes (b: BINARY_TREE [G]) is -- Adjust number of nodes from those in b. do if b /= Void then nodes := nodes + b.nodes end

Chair of Software Engineering OOSC - Summer Semester Other examples in OOSC-2  Coroutines  Locking a resource — semaphores  An elevator control system  A watchdog mechanism (execute an action, but take control back if not done after t seconds)

Chair of Software Engineering OOSC - Summer Semester Two-level architecture SCOOP ….NETTHREADS

Chair of Software Engineering OOSC - Summer Semester NET remoting library  Provides a good basis for SCOOP:  AppDomains: Partition object set  Marshal by Value, Marshal by Reference  All types are potentially remotable  Threading library

Chair of Software Engineering OOSC - Summer Semester AppDomains “Almaviva”name landlord loved_one O1 “Figaro” O2 “Susanna” O3 Context AppDomain Process

Chair of Software Engineering OOSC - Summer Semester Challenges  Conceptual:  Systematic approach to deadlock prevention  Precise fairness policies  Proof rules, actual proofs.  Organizational:  Language & compiler integration But also an opportunity  Building industrial-grade software in a university But: ETH CS tradition; Dept and university support

Chair of Software Engineering OOSC - Summer Semester End of lecture 25