Professional Documents
Culture Documents
Object-Oriented
Programming
Piotr Nienaltowski, Volkan
Arslan, Bertrand Meyer
Processor 2
Processor 1
Processors
• Not just mean physical CPU
• Threads
• Processes
• Computers in a distributed system
• Application Domain
Access control policy
• Separate calls are valid if the target of the call is
an argument of the enclosing routine
while( !lock(a) )
f() is
wait( a )
do
SOME_ROUTINE(a
) …
a.f() end
release(a)
Access control policy
• Using Design by Contract
store(buffer: separate BUFFER; value: INTEGER) is
require -- precondition
buffer_not_full: not buffer.is_full
do
buffer.put(value)
ensure -- postcondition
buffer_not_empty: not buffer.is_empty
end
…
buf: separate BUFFER
store(buf, 20)
Wait by necessity
• Client Objects
– do not need to wait for feature calls of a
supplier in order to call another feature
call
– must wait on query calls for all previous
calls to finish on the same supplier
Example
some_feature( x, y, z: separate CLASS ) is
do
x.f
y.f
x.g
z.f
y.g
v := x.is_empty -- wait for x.f and x.g
v := x.value > y.value -- wait for y.f and y.g
end
Producer/Consumer
Example
ProduceAndConsume( p: separate PRODUCER, c: separate
CONSUMER ) is
do
c.consume_n(5);
p.produce_n(5);
end
…
buf: separate BUFFER
consumer: separate CONSUMER
producer: separate PRODUCER
create c.make(buf)
create p.make(buf)
ProduceAndConsume(producer, consumer)
Producer
produce_n (n: INTEGER) is store (buffer: separate BUFFER [INTEG
local value: INTEGER) is
value: INTEGER require
i: INTEGER buffer_not_full: not buffer.is_ful
do value_provided: value /= Void
from i := 1 do
until i > n buffer.put (value)
loop end
value :=
random_gen.next
store (buf, value)
i := i + 1
end
end
end -- class PRODUCER
Consumer
consume_n (n: INTEGER) is consume_one (buffer:
local separate
i: INTEGER BUFFER [INTEGER]) is
do require
from i := 1 buffer_specified: buffer /=
until i > n Void
loop buffer_not_empty: not
buffer.is_empty
consume_one (buf)
do
i := i + 1 value := buffer.item
end buffer.remove
end end
Producer/Consumer
Example
ProduceAndConsume( p: separate PRODUCER, c: separate
CONSUMER ) is
do
c.consume_n(5);
p.produce_n(5);
end
…
buf: separate BUFFER
consumer: separate CONSUMER
producer: separate PRODUCER
create c.make(buf)
create p.make(buf)
ProduceAndConsume(producer, consumer)
Reusing old software
• Support for inheritance allows for
reuse of non-concurrent software
• May only require a simple wrapper
class
separate class BUFFER
inherit QUEUE
end
Distributed Computing
• Processors can be Computers in the
network
• Concurrency Control File
– maps processors to physical addresses
• machines
• processes
• etc.
• Can take advantage of .NET Remoting
library
Distributed Computing