1 / 138

SCOOP – Eiffel Concurrency

SCOOP – Eiffel Concurrency. Slides adapted from Bertrand Meyer, ETH. Lecture 21: Concurrency and real-time systems. Overview. Goal Basics of the SCOOP model Architecture and implementation of SCOOP Examples Basics of the real-time systems Timing and real-time extensions

egan
Download Presentation

SCOOP – Eiffel Concurrency

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SCOOP – Eiffel Concurrency Slides adapted from Bertrand Meyer, ETH Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM0

  2. Lecture 21: Concurrency and real-time systems Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM1

  3. Overview • Goal • Basics of the SCOOP model • Architecture and implementation of SCOOP • Examples • Basics of the real-time systems • Timing and real-time extensions • Conclusion and future work Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM2

  4. Goal Extend a pure, strongly typed, object-oriented language (Eiffel, …) with • a simple, general and powerful concurrency and distribution model ( SCOOP) • and extend SCOOP to support real-time programming Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM3

  5. The SCOOP model • Simple Concurrent Object-Oriented Programming • High-level concurrency mechanism • Full use of inheritance and other object-oriented techniques • Applicable to many physical setups: multiprocessing, multithreading, distributed execution, etc. Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM4

  6. Object-oriented computation To perform a computation is • to use certain processors • to apply certain actions • to certain objects. Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM5

  7. What makes an application concurrent? Processor:autonomous thread of control supporting sequential execution of instructions on one or more objects Can be implemented as: • Computer CPU • Process • Thread • AppDomain (.NET) … Mapping of processors to computational resources through Concurrency Control File (CCF) Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM6

  8. Feature call (synchronous call) • Fundamental scheme of O-O computation: feature call x.f (a) • x:CLASS_X Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM7

  9. Feature call (synchronous call) • Fundamental scheme of O-O computation: feature call x.f (a) • x:CLASS_X Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM8

  10. Feature call (synchronous call) • Fundamental scheme of O-O computation: feature call x.f (a) • x:CLASS_X Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM9

  11. Feature call (synchronous call) • Fundamental scheme of O-O computation: feature call x.f (a) • x:CLASS_X Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM10

  12. Feature call (synchronous call) • Fundamental scheme of O-O computation: feature call x.f (a) • x:CLASS_X Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM11

  13. Separate feature call (asynchronous call) • Fundamental scheme of O-O computation: feature call x.f (a) • x:separateCLASS_X Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM12

  14. Feature call (synchronous call) • Fundamental scheme of O-O computation: feature call x.f (a) • x:CLASS_X Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM13

  15. Separate feature call (asynchronous call) • Fundamental scheme of O-O computation: feature call x.f (a) • x:separateCLASS_X Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM14

  16. Access control policy • Target of a separate call must be formal argument of enclosing routine: store (b:separate BUFFER [G]; value: G)is -- Store value into b. do b.put (value) end • To obtain exclusive access to a separate object, use it as argument of call: my_buffer:separate BUFFER [INTEGER] createmy_buffer store (my_buffer, 10) Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM15

  17. From preconditions to wait-conditions Contracts in Eiffel store (b: BUFFER [G]; value: G)is -- Store value into b. require not b.is_full value /= Void do b.put (value) ensure not b.is_empty end ... store (my_buffer, 10) • If b is separate, precondition becomes wait condition (instead of correctness condition) Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM16

  18. From preconditions to wait-conditions Contracts in Eiffel store (b:separate BUFFER [G]; value: G)is -- Store value into b. require not b.is_full value /= Void do b.put (value) ensure not b.is_empty end ... store (my_buffer, 10) • If b is separate, precondition becomes wait condition (instead of correctness condition) Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM17

  19. Synchronization • No special mechanism needed for client to resynchronize with supplier after separate call. • The client will wait only when it needs to: x.f x.g (a) y.f … value := x.some_query Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM18

  20. Synchronization • No special mechanism needed for client to resynchronize with supplier after separate call. • The client will wait only when it needs to: x.f x.g (a) y.f … value := x.some_query Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM19

  21. Synchronization • No special mechanism needed for client to resynchronize with supplier after separate call. • The client will wait only when it needs to: x.f x.g (a) y.f … value := x.some_query … if value > 10then…end Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM20

  22. Synchronization • No special mechanism needed for client to resynchronize with supplier after separate call. • The client will wait only when it needs to: x.f x.g (a) y.f … value := x.some_query … if value > 10then…end • This mechanism is called wait by necessity. Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM21

  23. CCF – Mapping of processors to physical resources • Location of processors need not be specified at compile time • On the fly specification with Concurrency Control File (CCF) creation system "goethe" (4): "c:\prog\appl1\appl1.exe" "beethoven" (2): "c:\prog\appl2\appl2.dll" "Current" (5): "c:\prog\appl3\appl3.dll" end external Database_handler: "daimler_benz" port 9000 ATM_handler: "duerer" port 8001 end default port: 8001; instance: 10 end Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM22

  24. CCF – Mapping of processors to physical resources • Location of processors need not be specified at compile time • On the fly specification with Concurrency Control File (CCF) creation system "Current": "c:\prog\appl1\appl1.exe" end end end external Database_handler: "daimler_benz" port 9000 ATM_handler: "duerer" port 8001 end default port: 8001; instance: 10 end Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM23

  25. SCOOP platform-independent .NET Compact Framework .NET POSIXThreads … Two-level architecture of SCOOP • SCOOP can be implemented in several environments • Microsoft .NET is our current platform Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM24

  26. Implementation • SCOOPLI for .NET and others • Library implementation of SCOOP in its original version • Uses Remoting and Threading capabilities of .NET • Uses Threading capabilities of the .NET CF on the RTOS Windows CE .NET (and/or other RTOS: VxWorks, etc.) Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM25

  27. Example: Bounded buffers separate class BOUNDED_BUFFER [G] inherit BOUNDED_QUEUE[G] end Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM26

  28. Example: Bounded buffers indexing description: "Encapsulation of access to bounded buffers" class BUFFER_ACCESS [G] feature put (q: BOUNDED_BUFFER [G]; x: G)is -- Insert x into q, waiting if necessary until there is room. require not q.full do q.put (x) ensure not q.empty end Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM27

  29. Example: Bounded buffers remove (q: BOUNDED_BUFFER [G])is -- Remove an element from q, waiting if necessary -- until there is such an element require not q.empty do q.remove ensure not q.full end item (q: BOUNDED_BUFFER [G]): G is -- Oldest element not yet consumed require not q.empty do Result := q.remove end end -- classBUFFER_ACCESS [G] Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM28

  30. Example: Bounded buffers Usage of bounded buffers my_buffer_access: BUFFER_ACCESS [INTEGER] my_bounded_buffer: BOUNDED_BUFFER [INTEGER] createmy_buffer_access createmy_bounded_buffer my_buffer_access.put (my_bounded_buffer, 25) my_buffer_access.put (my_bounded_buffer, 50) my_result := my_buffer_acces.item (my_bounded_buffer) Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM29

  31. Example: Dining philosophers separate class PHILOSOPHER inherit GENERAL_PHILOSOPHER PROCESS rename setup as getup undefine getup end feature {BUTLER} step is -- Perform a philosopher’s tasks. do think eat (left, right) end eat (l, r: separate FORK) is -- Eat, having grabbed l and r. do … end end -- class PHILOSOPHER Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM30

  32. Class PROCESS indexing description: "The most general notion of process" deferred classPROCESS feature -- Status report over: BOOLEANis -- Must execution terminate now? deferred end feature -- Basic operations setupis -- Prepare to execute process operations (default: nothing). do end stepis -- Execute basic process operations. deferred end Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM31

  33. Class PROCESS (cont.) wrapupis -- Execute termination operations (default: nothing). do end feature -- Process behavior liveis -- Perform process lifecycle. do fromsetupuntiloverloop step end wrapup end end -- classPROCESS Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM32

  34. Class GENERAL_PHILOSOPHER class GENERAL_PHILOSOPHER create make feature-- Initialization make (l, r:separate FORK)is -- Define l as left and r as right forks. do left := l right := r end feature{NONE}-- Implementation left:separate FORK right:separate FORK Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM33

  35. Class GENERAL_PHILOSOPHER (cont.) getup is -- Take any necessary initialization action. do end think is -- Any appropriate action or lack thereof do end end -- class GENERAL_PHILOSOPHER class FORK end Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM34

  36. Class BUTLER class BUTLER create make feature count: INTEGER -- The number of both philosophers and forks launch is -- Start a full session. local i: INTEGER do from i := 1 until i > count loop launch_one (participants @ i) i := i + 1 end end Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM35

  37. Class BUTLER (cont.) feature --{NONE} launch_one (p: PHILOSOPHER)is -- Let one philosopher start his actual life. do p.live end participants: ARRAY [PHILOSOPHER] cutlery: ARRAY [FORK] feature{NONE}-- Initialization make (n: INTEGER)is -- Initialize a session with n philosophers. require n >= 0 do count := n create participants.make (1, count) create cutlery.make (1, count) make_philosophers launch ensure count = n end Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM36

  38. Class BUTLER (cont.) make_philosophers is -- Set up philosophers. local i: INTEGER p: PHILOSOPHER left, right:separate FORK do from i := 1 until i > count loop left := cutlery @ i right := cutlery @((i \\ count) + 1) create p.make (left, right) participants.put (p, i) i := i + 1 end end invariant count >= 0 participants.count = count cutlery.count = count end-- class BUTLER Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM37

  39. Definition: Real-time system Real-time system (Young, 1982): Any information processing activity or system which has to respond to externally generated input stimuli within a finite and specified period. • The correctness of a real-time system depends not only on the logical result of the computation, but also on the timeat which the results are produced ...  a correct but a late response is as bad as awrong response ... Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM38

  40. Hard and soft real-time systems • Hard real-time Systems where it is absolutely imperative that responses occur within the required deadline. E.g. flight control systems, … • Soft real-time Systems where deadlines are important but which will still function correctly if deadlines are occasionally missed.E.g. data acquisition system, … A single real-time system may have both hard and soft real-time subsystems Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM39

  41. Definition: Embedded system Embedded system: The computer is an information processing component within (embedded in) a larger engineering system. (e.g. washing machine, process control computer, ABS ― Anti Blocking System in vehicles, ...) Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM40

  42. Characteristics of real-time systems • Large and complex (up to 20 million lines of code estimated for the Space Station Freedom) • Concurrent control of separate system components • Facilities to interact with special purpose hardware • Extreme reliable and safe • Guaranteed response times Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM41

  43. Components of a real-time system • Hardware (CPU, sensors, ADC, DAC, …) • Real-time OS (e.g VxWorks, QNX, Windows CE .NET, …) • Real-time application and real-time runtime system (e.g. Ada, Real-Time Java, C with Real-Time Posix and hopefully soon Real-Time SCOOP ) Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM42

  44. A simple embedded and real-time example Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM43

  45. A simple embedded and real-time example Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM44

  46. Real-Time Facilities • Notion of time • Clocks • Delays • Timeouts • Temporal scopes Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM45

  47. Notion of time • Linearity: • Transitivity: • Irreflexibility: • Density:  The passage of time is equated with a real line. Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM46

  48. Access to a Clock • Direct access to the environment's time frame(e.g. transmitters for UTC = Universal Time Coordinated, UTC service of GPS) • Using an internal hardware clock that gives an adequate approximation to the passage of time in the environment Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM47

  49. Clocks in Real-Time Java • java.lang.System.currentTimeMillis returns the number of milliseconds since 1/1/1970 GMT and is used by java.util.Date • Real-time Java adds real-time clocks with high resolution time types Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM48

  50. RT Java Time Types (1) public abstract class HighResolutionTime implements java.lang.Comparable { public abstract AbsoluteTime absolute(Clock clock, AbsoluteTime destination); ... public boolean equals(HighResolutionTime time); public final long getMilliseconds(); public final int getNanoseconds(); public void set(HighResolutionTime time); public void set(long millis); public void set(long millis, int nanos); } Slides based on Object Oriented Software Construction 2014-09-23 6:27 PM49

More Related