IN[59]570 Exercise Session 2
Introduction to Oblig 1.
Joachim Tilsted Kristensen
joachkr@ifi.uio.no
University of Oslo, February 02, 2023
Review the revised exercises from last time, and check your solution with
the solutions in solutions/session-1
on GitHub.
The Kilroy program.
Here is a more advanced version of the hello world
program, that prints to
standard out of all connected nodes. Extend the program, to use move
.
Consult the Emerald language report for the semantics of move
.
% - -
% { 0 0 }
% +===================oOO===(_)===OOo===============+
const WotchIt <-
object program
process
% Greetings.
const home <- locate self
stdout.putstring[ "Starting at " || home$LNN.asstring || "\n" ]
% A counter, and a list of places to go.
var network : NodeList <- home$activenodes
% Meet up all nodes in the network.
for contact in network
const here <- locate self
const host <- contact$theNode
% Remote Method invocation.
host$stdout.putstring["Comming over. Kind regards, Kilroy\n"]
% ... call move here ...
end for
% Report.
stdout.putstring["I am done\n"]
end process
end program
The object program
, should move it self to the other nodes and then back.
Monitors and conditions
The keyword monitor
can generally be put in the same places as the word
object
, and it defines a "monitored" object. (Read Tony Hoare's
"Monitors : an operating systems concept" and come back here).
const wait_for_me <-
monitor class i_am_late
const invocation <- Condition.create
export operation stop
wait invocation
end stop
export operation come_on
signal invocation
end come_on
end i_am_late
The object wait_for_me
, is a monitored object. It essentially means that
you can call a method on it, with guaranteed mutual exclusion.
It starts by creating a condition
. You wait for this condition by calling
stop
, and you can signal it by calling come_on
.
- Make an object that waits for
wait_for_me
and prints to the screen. - Make another object that calls
come_on
. - Run it a couple of times.
- Does it work?
Challenge.
-
Extend
wait_for_me
with a methodsemi_stop
that takes an extra argumentt
of typetime
. The semantics ofsemi_stop
should be that ifinvocation
has not been signalled withint
time.wait_for_me
should continue without waiting further. -
What do you need to extend the cyclic barrier from the Oblig to support a timeout?
-
Extend the cyclic write barrier from the oblig with an API call that waits for the barrier for 10 seconds, and then continues if the barrier has not been signalled.