Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 6:Computational Model (based on work with Piotr Nienaltowski)

Similar presentations


Presentation on theme: "Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 6:Computational Model (based on work with Piotr Nienaltowski)"— Presentation transcript:

1 Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 6:Computational Model (based on work with Piotr Nienaltowski)

2 2 Basic Idea of OO Computation To perform a computation is To apply certain actions To certain objects Using certain processors ActionObject Processor

3 3 Processors Processor: a thread of control supporting sequential execution of instructions on one or several objects. All actions on a given object are executed by its handling processor. No shared access to objects! We say that the object is handled by its processor. This relationship is fixed, i.e. we do not consider migration of objects between processors. Each processor, together with all object it owns, can be seen as a sequential subsystem. A (concurrent) software system is composed of such subsystems. By design a SCOOP system is free of low-level data races.

4 4 Processors P1 o1 o3 o2o4 P2 o5 o9 o7 P3 o11 o8 o6o12

5 5 Processors Processor is an abstract concept Do not confuse it with a CPU! A processor can be implemented as: Process Thread Web service.NET AppDomain …

6 6 Synchronous Feature Call f (a: A) require a /= Void do … end c x x: X previous_instruction x.f (a) next_instruction P1 c x

7 7 Asynchronous Feature Call f (a: A) require a /= Void do … end c x x: separate X previous_instruction x.f (a) next_instruction P1 c P2 x

8 8 Separate Objects Calls to non-separate objects are synchronous. Calls to separate objects are asynchronous. QUIZ: Which objects are separate here? P1P1 o1 P2 o2 o3

9 9 Separate Entities Separate entities are declared with separate keyword as in x: separate X. Does a separate entity always denote a separate object? Separate entities denote potentially separate objects. P1 o1 P2 o2 o3 x y y y: separate X r (x: separate X) do y := x.y -- Is y a separate entity? -- Does it denote a separate object? end

10 10 Synchronization Processors are sequential. Concurrency is achieved by interplay of several processors. Processors need to synchronize. Three forms of synchronization in SCOOP mutual exclusion condition synchronization wait-by-necessity

11 11 Why do we need mutual exclusion? P1 o1 P2 o2 o3 my_stack y P3 o6 o8 y my_stack -- P1 my_stack.push (5) y := my_stack.top -- P3 my_stack.push (100) y := my_stack.top

12 12 Mutual Exclusion in SCOOP Require target of separate call to be formal argument of enclosing routine. Body (do … end) of enclosing routine is a critical section with respect to its separate formal arguments. push_and_retrieve (s: separate STACK [INTEGER]; value: INTEGER) -- Push value on top of s then retrieve top of s and assign it to y. do s.push (value) y := s.top end my_stack: separate STACK [INTEGER] … push_and_retrieve (my_stack, 5) -- Now we are we sure that y=5 No other processor can access s in the meantime.

13 13 Wait Rule A routine call with separate arguments will execute when all corresponding processors are available. The processors are held exclusively for the duration of the routine.

14 14 Condition Synchronization Very often client only wants to execute certain feature if some condition (guard) is true. store (buffer: separate BOUNDED_BUFFER [INTEGER]; value: INTEGER) is -- Store value into buffer. require buffer_not_full: not buffer.is_full do buffer.put (value) end my_buffer: separate BOUNDED_BUFFER [INTEGER] … store (my_buffer, 5) Hey, it’s a precondition, not a guard! How should it work?

15 15 From Preconditions to Wait-Conditions store (buffer: BUFFER [INTEGER]; value: INTEGER) -- Store value into buffer. require buffer_not_full: not buffer.is_full value > 0 do buffer.put (value) ensure buffer_not_empty: not buffer.is_empty end... store (my_buffer, 5) precondition postcondition

16 16 Why new semantics? Preconditions are obligations that the client has to satisfy before the call. The fulfillment of the precondition is not only in our hands. if not my_buffer.is_full and then 5 > 0 then store (my_buffer, 5) end Is the precondition of store satisfied?

17 17 Wait Rule Revisited Wait Rule A routine call with separate arguments will execute when all corresponding processors are available and the precondition is satisfied. The processors are held exclusively for the duration of the routine.

18 18 Resynchronizing Clients and Suppliers … x.f x.g (a) y.f … Pc Px Py x.f x.g(a) y.f

19 19 Wait By Necessity There is no explicit mechanism for resynchronization after separate call. The client will only wait when it needs to. This is called wait-by-necessity. x.f; x.g (a); y.f … value := x.some_query wait here

20 20 Do we really need to wait? Can we do better than that? It does not change the basic SCOOP model. Consider it to be an optimisation x.f; x.g (a); y.f … value := x.some_query x.f; y.f value := value + 1 We only need to wait here.

21 21 Too much Locking r (x: separate X; y: separate Y; z: separate Z) require some_precondition local my_y: separate Y my_z: separate Z do x.f my_y := y x.g my_z := z s (z) end

22 22 Eager Locking Eager locking policy has two major drawbacks Increases danger of deadlock References cannot be passed around without locking the corresponding objects; programmers have no real control over the locks

23 23 Wait Rule Revisited Wait Rule A routine call with separate arguments will execute when all processors of attached formal arguments are available and the precondition is satisfied. The processors are held exclusively for the duration of the routine. Together with the valid target rule the wait rule ensures the absence of high-level data races.

24 24 Just enough Locking r (x: separate X; y: detachable separate Y; z: detachable separate Z) require some_precondition local my_y: detachable separate Y my_z: detachable separate Z do x.f my_y := y x.g my_z := z s (z) end

25 25 Summary 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.

26 26 Summary mutual exclusion Locking through argument passing Routine body is critical section Flexible locking increased parallelism condition synchronization wait-semantics for preconditions re-synchronisation of client and supplier: wait-by-necessity


Download ppt "Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 6:Computational Model (based on work with Piotr Nienaltowski)"

Similar presentations


Ads by Google