Hardware Reference
In-Depth Information
guard, which is the same as the value
true
. When an operation is invoked, all of its
guards are evaluated in an unspecified order. If all of them are
false
, the invoking
process is delayed until one becomes
true
. When a guard is found that evaluates to
true
, the block of statements following it is executed. Figure 8-48 depicts a
stack
object with two operations,
push
and
pop
.
Object implementation stack
;
top:integer;
# storage for the stack
stack:
array
[integer 0..N
−
1]
of
integer;
operation
push(item: integer);
# function returning nothing
begin
guard
top<N
−
1
do
stack[top] := item;
# push item onto the stack
top := top + 1;
# increment the stack pointer
od
;
end
;
operation
pop( ): integer;
# function returning an integer
begin
guard
top>0
do
# suspend if the stack is empty
top := top
−
1;
# decrement the stack pointer
return stack[top];
# return the top item
od
;
end
;
begin
top := 0;
# initialization
end
;
Figure 8-48.
A simplified ORCA stack object, with internal data and two operations.
Once a
stack
has been defined, variables of this type can be declared, as in
s, t: stack;
which creates two stack objects and initializes the
top
variable in each to 0. The
integer variable
k
can be pushed onto the stack
s
by the statement
s$push(k);
and so forth. The
pop
operation has a guard, so an attempt to pop a variable from
an empty stack will suspend the called until another process has pushed something
on the stack.
Orca has a
fork
statement to create a new process on a user-specified proc-
essor. The new process runs the procedure named in the
fork
statement. Parame-
ters, including objects, may be passed to the new process, which is how objects be-
come distributed among machines. For example, the statement
for
i
in
1..n
do fork
foobar(s)
on
i;
od
;