Sunday, March 22, 2009

Ch8, Ex13

Only method Trans inside TMClass is changed to following:
meth Trans(P ?R TS)
T=trans(stamp:TS save:{NewDictionary} body:P
state:{NewCell running} result:R)
proc {ExcT C X Y} S1 S2 in
{proc {$}
{@tm getlock(T C S1)}
if S1==halt then raise Halt end end
{@tm savestate(T C S2)} {Wait S2}
{Exchange C.state X Y}
proc {AccT C ?X} {ExcT C X X} end
proc {AssT C X} {ExcT C _ X} end
proc {AboT} {@tm abort(T)} R=abort raise Halt end end
SubThread %Change: New Addition
%Change here
thread {NewThread
proc {$}
try Res={T.body t(access:AccT assign:AssT
exchange:ExcT abort:AboT
in {@tm commit(T)} R=commit(Res)
catch E then
if E\=Halt then {@tm abort(T)} R=abort(E) end
end end SubThread} end

If one needs to start another thread inside the transaction then it can use {T.subthread <0-argument-proc>} to do so.

No comments:

Post a Comment