Download SilTools Developer`s Guide

Transcript
Concurrency
tclosures
A tclosure is to a task what a closure is to a function: a passable data
item whose value is a task rather than a function.
Example 10.8
task delay_and_print(x:integer);
begin
delay(x);
writeln('delayed for ',x,' at ',clock)
end;
delayc == mk_closure("delay_and_print,task(lispob,integer));
task five_times(x:tclosure(lispob,integer);n:integer);
begin
for i := 1 to 5 do x(n);
end;
clock := 0;
five_times(delayc,4);
This yields the output
delayed for 4 at 4.000000
delayed for 4 at 8.000000
delayed for 4 at 12.000000
delayed for 4 at 16.000000
delayed for 4 at 20.000000
Notice that the type of a task with no return value is task(lispob,integer),
and that the type of delayc is tclosure(lispob,integer).
10-14
SilTools