Title: Simple Concurrent Object-Oriented Programming
1Simple Concurrent Object-Oriented Programming
2SCOOP Outline
- PRODUCER-CONSUMER example
- Mapping from SCOOP to EiffelTHREADs
3Concurrency
- 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
4SCOOP
A single new keyword (separate) provides for a
full-fledged concurrency mechanism !!!
5SCOOP
SCOOP Simple Concurrent Object-Oriented
Programming. Defined by Bertrand Meyer in OOSC in
1997
Implementations
- Compton. Changes in the open source SmallEiffel
compiler
- 3. SCOOP in the .NET framework
6SCOOP Generator
Object-Oriented Design
Design By Contract
- Simple and intuitive concurrency model of SCOOP
- Concurrent programs using SCOOP
7SCOOP Generator
- Eiffel SCOOP -gt Eiffel THREAD
- Standard Eiffel code (mutexes and THREADs)
Advantages
- Target code is cross-platform
Disadvantage Debugging on a target code
8Producer-Consumer Java Solution
9Producer-Consumer SCOOP Solution
- - same behaviour as the Java solution
- only one extra keyword separate is used ()
- uses contracts with all the benefits of DbC
10ROOT_CLASS
- class ROOT_CLASS creation
- make
- feature
- b separate BUFFER
- p PRODUCER -- declared separate
- c CONSUMER -- declared separate
- make is
- -- Creation procedure.
- do
- create b.make
- create p.make(b)
- create c.make(b)
- end
- end
11Bounded BUFFER
- class BUFFER creation
- make
- feature
-
- put (xINTEGER) is
- require count lt 3
- do q.put(x)
- ensure count old count 1 and q.has (x)
- end
-
- remove is
- require count gt 0
- do q.remove
- ensure count old count - 1
- end
-
12PRODUCER
- separate class PRODUCER creation
- make
- feature
- buffer separate BUFFER
- make (b separate BUFFER) is do keep_producing
end - keep_producing is do produce(buffer,i) end
- produce (b separate BUFFER iINTEGER) is
- require b.count lt 2
- do b.put(i)
- ensure b.has(i)
- end
- end
13CONSUMER
- separate class CONSUMER creation
- make
- feature
- buffer separate BUFFER
- make (b separate BUFFER) is do keep_consuming
end - keep_consuming is do consume(buffer) end
-
- consume (b separate BUFFER) is
- require b.count gt 0
- do b.remove
- ensure b.count old b.count - 1
- end
- end
14Synchronization in SCOOP
- A call to the routine produce 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
15Preconditions in SCOOP
- if not buffer.full then
- Â Â Â buffer.put(value)
- produce (b separate BUFFER i INTEGER) is
require b.count lt 2 - i gt 0 do b.put (i) end
16Mapping to Eiffel THREAD
- separate class
- ROOT_CLASS
class ROOT_CLASS inherit THREAD_CONTROL
feature
feature request_pended INTEGER_REF requests_pende
d_mutexMUTEX
bseparate BUFFER pPRODUCER
bBUFFER b_mutex MUTEX pPRODUCER
17Mapping to Eiffel 2
make is do requests_pended 1
create b.make
b_mutex.lock create b.make b_mutex.unlock
18Mapping 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_ROUTI
NE")
19Mapping to Eiffel 4
same as p.make
requests_pended_mutex.lock requests_pended.copy
(requests_pended-1) requests_pended_mutex.unlock
end
join_all end
20Contributions
- Analysis of Meyers SCOOP with a view to
implementation semantics of SCOOP via Comptons
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
21Thank You