Sunday, March 22, 2009

Ch8, Ex4

A very naive version
declare
fun {SlowNet3 Obj Time}
D = {NewDictionary}
proc {RemoveTerminatedThreads L}
case L of X|Xr then
if {Thread.state X}==terminated
then {D.remove X} end
[] nil then skip
end
end
in
proc {$ M}
Old New T = {Thread.this} in
{RemoveTerminatedThreads {D.keys}}
if {Not {D.member T}} then
{D.put T {NewCell unit}}
end
{Exchange {D.get T} Old New}
thread
{Delay Time}
{Wait Old}
{Obj M}
New=unit
end
end
end
Note: We can't use the oz dictionary as it doesn't allow us to put result of {Thread.this} as key into it. Instead, the dictionary implementation done for Chapter-6, Ex-13 at http://ctamcp-himanshu.blogspot.com/2009/02/ch6-ex13.html is to be used.

No comments:

Post a Comment