Top Banner
Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland http://se.inf.ethz.ch
31

Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

SCOOP: an introduction

Bertrand Meyer

Chair of Software Engineering,ETH Zurich, Switzerland

http://se.inf.ethz.ch

Page 2: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Why SCOOP?

Extend object technology with general and powerful concurrency support

Provide the industry with simple techniques for parallel, distributed, internet, real-time programming

Make programmers sleep better!

Page 3: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

The SCOOP model

Simple Concurrent Object-Oriented Programming

High-level concurrency mechanism

Fully uses inheritance and other O-O techniques

Applicable to many physical setups: multiprocessing, multithreading, distributed execution, Web services...

Based on Design by Contract and Eiffel concepts

Page 4: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Object-oriented computation

To perform a computation is to use certain processors to apply certain actions to certain objects.

Processor

Actions Objects

Page 5: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

What makes an application concurrent?

Processor: autonomous thread of control supporting

sequential execution of instructions on one or more objects

Can be implemented as: Process Thread AppDomain (.NET) Web service

Processor

Actions Objects

Page 6: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Feature call: synchronous

x: CLASS_X...x.f (a)

Object 1 Object 2

(CLASS_T ) (CLASS_X)

previous_instruction

x . f (a)next_instruction

Processor

f (a: A) require a /= Void ensure not a.empty

Page 7: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Separate feature call (asynchronous)

x: separate CLASS_X...x.f (a)

(CLASS_T) (CLASS_X)

Processor 1 Processor 2

Object 1 Object 2

previous_instruction

x . f (a)next_instruction

f (a: A) require a /= Void ensure not a.empty

Page 8: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Access control policy

Target of separate call must be formal argument of enclosing routine: store (buffer: separate BUFFER [INTEGER]; value: INTEGER) is

-- Store value into buffer. do

buffer.put (value) end

Call with separate argument gives exclusive access: store (my_buffer, 10)

Page 9: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Contracts in Eiffel

store (buffer: BUFFER [INTEGER]; value: INTEGER) is-- Store value into buffer.

requirenot buffer.is_fullvalue > 0

dobuffer.put (value)

ensurenot buffer.is_empty

end...store (my_buffer, 10)

If b is separate, precondition becomes wait condition (instead of correctness condition)

Precondition

Page 10: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

From preconditions to wait-conditions

store (buffer: separate BUFFER [INTEGER]; value: INTEGER) is

-- Store value into buffer. require

not buffer.is_fullvalue > 0

dobuffer.put (value)

ensurenot buffer.is_empty

end...store (my_buffer, 10)

If buffer is separate,.

On separate target, precondition becomes wait condition

Page 11: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Wait by necessity

No special mechanism for client to resynchronize with supplier after separate call.

The client will wait only when it needs to:x.fx.g (a)y.f…value := x.some_query

Wait here!

Page 12: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Duels

Problem: Impatient client (challenger) wants to snatch object from another client (holder)

Can’t just interrupt holder, service challenger, and resume holder: would produce inconsistent object.

But: can cause exception, which will be handled safely.

Page 13: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Challenger →

↓ Holder

normal_service immediate_service

retain Challenger waits Exception in challenger

yield Challenger waits Exception in holder; serve challenger

Duels

Page 14: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Mapping processors to physical resources

Concurrency Control File (CCF)

create system

"lincoln" (4): "c:\prog\appl1\appl1.exe" "roosevelt" (2): "c:\prog\appl2\appl2.dll"

"Current" (5): "c:\prog\appl3\appl3.dll" endexternal Database_handler: "jefferson" port 9000 ATM_handler: "gates" port 8001enddefault port: 8001; instance: 10end

Page 15: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Two-level architecture of SCOOP

Can be implemented on various platforms

Microsoft .NET is our reference platform

SCOOPplatform-independent

.NET.NET

CompactFramework

POSIXThreads

Page 16: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

SCOOPLI: Library for SCOOP

Library-based solution

Implemented in Eiffel for .NET(from Eiffel Software:EiffelStudio / ENViSioN! for Visual Studio.NET)

Aim: try out solutions without bothering with compiler issues

Can serve as a basis for compiler implementations

Page 17: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

separate client separate supplier

Each separate client & separate supplier handled by different processor

Class gets separateness through multiple inheritance:

SEPARATE_ SUPPLIER X

SEPARATE_X

SCOOPLI concepts

Page 18: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

SCOOPLI emulation of SCOOP concepts

SCOOP SCOOPLI

x: separate Xx: X -- class X is separate

x: SEPARATE_X -- SEPARATE_X inherits from X and -- SEPARATE_SUPPLIER

r (x, y) -- x and y are separate

r (x: separate X; y: separate Y) is require not x.is_empty y.count > 5 i > 0 -- i non-separate

x /= Void do ... end

separate_execute ([x, y], agent r (x, y), agent r_precondition) r_precondition: BOOLEAN is do Result := not x.is_empty and y.count > 5 end -- client class inherits from -- class SEPARATE_CLIENT

Page 19: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

SCOOPLI Architecture

SEPARATE_HANDLER: locking; checking wait conditions; scheduling of requests

PROCESSOR_HANDLERs: execute separate calls;implement processors

Page 20: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Example: Dining philosophers

class PHILOSOPHER inheritPROCESS

renamesetup as getup

redefine step end

feature {BUTLER}step is do think ; eat (left, right)

end

eat (l, r: separate FORK) is -- Eat, having grabbed l and r.

do … endend

Page 21: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Example: Bounded buffer usage

Usage of bounded buffers

buff: BUFFER_ACCESS [MESSAGE]my_buffer: BOUNDED_BUFFER [MESSAGE]

create my_buffercreate buff.make (my_buffer)

buff.put (my_buffer, my_message)…buff.put (my_buffer, her_message)…my_query := buff.item (my_buffer)

Page 22: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Example: elevator

For maximal concurrency, all objects are separate

Inheritance

Client

Page 23: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Dynamic diagram

CABIN_BUTTON ELEVATOR

ENGINE

Scenario: Pressing the cabin button to move the elevator

1

2 4

1 Cabin button calls elevator.accept (target)

2 Elevator calls engine.move (floor)

3 Engine calls gui_main_window.move_elevator (cabin_number, floor)

4 Engine calls elevator.record_stop (position)

GUI_MAIN_WINDOW3

asynchronous call

synchronous call

Page 24: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Class BUTTON

separate class

BUTTON

feature

target: INTEGER

end

Page 25: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Class CABIN_BUTTON

separate class CABIN_BUTTON inherit BUTTON

feature cabin: ELEVATOR

request is-- Send to associated elevator a request to stop on level

target. do

actual_request (cabin) end

actual_request (e: ELEVATOR) is-- Get hold of e and send a request to stop on level target.

doe.accept (target)

endend

Page 26: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Class ELEVATOR

separate class ELEVATOR feature {BUTTON, DISPATCHER}

accept (floor: INTEGER) is-- Record and process a request to go to floor.

dorecord (floor)if not moving then process_request end

end

feature {MOTOR}

record_stop (floor: INTEGER) is-- Record information that elevator has stopped on

floor. do

moving := False ; position := floor ; process_request end

Page 27: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Class ELEVATORfeature {NONE} -- Implementation

process_request is-- Handle next pending request, if any.

local floor: INTEGER doif not pending.is_empty then floor := pending.item ; actual_process (puller, floor) pending.removeend

end

actual_process (m: MOTOR; floor: INTEGER) is-- Handle next pending request, if any.

domoving := true ; m.move (floor)

end

feature {NONE} -- Implementationpuller: MOTOR ; pending: QUEUE [INTEGER]

end

Page 28: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Class MOTOR

separate class MOTOR feature {ELEVATOR}

move (floor: INTEGER) is

-- Go to floor; once there, report.

do

gui_main_window.move_elevator (cabin_number, floor)

signal_stopped (cabin)

end

signal_stopped (e: ELEVATOR) is

-- Report that elevator e stopped on level position.

do e.record_stop (position) end

feature {NONE}

cabin: ELEVATOR ; position: INTEGER -- Current floor level.

gui_main_window: GUI_MAIN_WINDOW

end

Page 29: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Distributed execution

Processors (AppDomains) located on different machines

.NET takes care of the "dirty work" Marshalling Minimal cost of inter-AppDomain calls

Computer1

AppDomain1

o1

o2

Computer2

AppDomain2

o3

o9

Computer3

AppDomain3

o4

o5

AppDomain4

o6

o7

o8

o9.f

o1.g

o6.f (o3)

o8.g

o4.f

Page 30: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Conclusions

SCOOP model Simple yet powerful Easier and safer than common concurrent techniques,

e.g. Java Threads Full concurrency support Full use O-O and Design by Contract Supports various platforms and concurrency

architectures One new keyword: separate

SCOOPLI library SCOOP-based syntax Implemented on .NET Distributed execution with .NET Remoting

Page 31: Chair of Software Engineering SCOOP: an introduction Bertrand Meyer Chair of Software Engineering, ETH Zurich, Switzerland .

Chair of Software Engineering

Current work

Prevent deadlock Statically checkable rules Run-time deadlock avoidance

Extend access control policy Multiple locking of separate objects

Extend for real-time Duel mechanism with priorities Timing assertions?

Integrate with Eiffel Software compiler

Direct support for processors in the CLI?