1 / 21

Simple Concurrent Object-Oriented Programming

Simple Concurrent Object-Oriented Programming. Nati Fuks. SCOOP Outline. SCOOP Introduction. Generator. SCOOP vs Java. PRODUCER-CONSUMER example. SCOOP Semantics. Mapping from SCOOP to Eiffel+THREADs. Concurrency. Concurrent programming is difficult e.g. Java Memory Flaw circa 1999

Télécharger la présentation

Simple Concurrent Object-Oriented Programming

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. Simple Concurrent Object-Oriented Programming Nati Fuks

  2. SCOOP Outline • SCOOP Introduction • Generator • SCOOP vs Java • PRODUCER-CONSUMER example • SCOOP Semantics • Mapping from SCOOP to Eiffel+THREADs

  3. Concurrency • Concurrent programming is difficult • e.g. Java Memory Flaw circa 1999 • A variety of mechanisms must be mastered • Thread class, synchronize, wait, notify, mutexes, monitor, critical regions • Problems such as deadlock, safety and liveness properties, inheritance anomaly

  4. SCOOP A single new keyword (separate) provides for a full-fledged concurrency mechanism !!!

  5. SCOOP SCOOP: Simple Concurrent Object-Oriented Programming. Defined by Bertrand Meyer in OOSC in 1997 • Compton. Changes in the open source SmallEiffel compiler Implementations: • 2. This work • 3. SCOOP in the .NET framework

  6. SCOOP Generator Why SCOOP Generator? Object-Oriented Design Design By Contract Simple and intuitive concurrency model of SCOOP What do we achieve? Concurrent programs using SCOOP

  7. SCOOP Generator • Eiffel SCOOP -> Eiffel + THREAD • Standard Eiffel code (mutexes and THREADs) • Eiffel Studio 5.4 Advantages • Pure Eiffel • Independence • Target code is cross-platform Disadvantage – Debugging on a target code

  8. Producer-Consumer Java Solution

  9. Producer-Consumer SCOOP Solution - same behaviour as the Java solution - only one extra keyword separate is used (||) - uses contracts with all the benefits of DbC

  10. ROOT_CLASS class ROOT_CLASS creation make feature b: separate BUFFER p: PRODUCER -- declared separate c: CONSUMER -- declared separate makeis -- Creation procedure. do create b.make create p.make(b) create c.make(b) end end

  11. Bounded BUFFER class BUFFER creation make feature put (x:INTEGER) is require count <= 3 do q.put(x) ensure count = old count + 1 and q.has (x) end removeis require count > 0 do q.remove ensure count = old count - 1 end …

  12. PRODUCER separateclass PRODUCER creation make feature buffer: separate BUFFER make (b: separate BUFFER) is do …keep_producing … end keep_producingisdo … produce(buffer,i) … end produce (b : separate BUFFER; i:INTEGER) is require b.count <= 2 do b.put(i) ensureb.has(i) end end

  13. CONSUMER separateclass CONSUMER creation make feature buffer: separate BUFFER make (b: separate BUFFER) is do …keep_consuming… end keep_consumingis do …consume(buffer)… end consume (b: separate BUFFER) is require b.count > 0 do b.remove ensureb.count = old b.count - 1 end end

  14. Synchronization in SCOOP A call to the routineproduce with a separate will block until: (a) the producer gets sole access to the buffer + (b) the buffer must not be full as indicated in the precondition

  15. Preconditions in SCOOP ifnot buffer.full then     buffer.put(value) • produce (b: separate BUFFER; i: INTEGER) isrequire b.count <= 2 • i >= 0do b.put (i)end

  16. Mapping to Eiffel + THREAD class ROOT_CLASS inherit THREAD_CONTROL separate class ROOT_CLASS feature feature request_pended: INTEGER_REF requests_pended_mutex:MUTEX b:separateBUFFER p:PRODUCER b:BUFFER b_mutex: MUTEX p:PRODUCER

  17. Mapping to Eiffel 2 make is do requests_pended := 1 make is do createb.make b_mutex.lock create b.make b_mutex.unlock

  18. Mapping to Eiffel 3 create p.make (b, b_mutex, requests_pended, requests_pended_mutex) create p.make (b) p.launch set_feature_to_do ([Current, "KEEP_PRODUCING_ROUTINE"])

  19. Mapping to Eiffel 4 same as p.make… create c.make (b) requests_pended_mutex.lock requests_pended.copy(requests_pended-1) requests_pended_mutex.unlock end join_all end

  20. Contributions • Analysis of Meyer’s SCOOP with a view to implementation – semantics of SCOOP via Compton’s subsystems • Based on the semantics of SCOOP – provided a mapping from SCOOP to Eiffel + Threads. • Generator parses SCOOP programs, flags syntax errors and automatically translates to portable executable code based on the mapping. • First full implementation of SCOOP • contracts • routine calls with multiple separate objects

  21. Thank You

More Related