Tuesday, February 17, 2009

Ch8, Ex2

I.Well, have a look at the kernel transform of the given program
local X in
local Y in
Y = X+1
{Exchange C X Y}
end
end

Now its clear to see that X is unbound and above program will keep on waiting for X to bind(that'll never happen) at line Y=X+1 and will never execute Exchange. Here is the program with a simple fix:
L = {NewLock}
lock L then X Y in
{Exchange C X Y}
Y = X+1
end

II. The simple fix that I have given above will not work in a language that doesn't have dataflow variables because it is *using* dataflow behavior of variable Y to work.

III. Another fix that doesn't use dataflow variables and hence, is possible in a language without dataflow variables:
L = {NewLock}
lock L then
C:=@C+1
end

No comments:

Post a Comment