CTM: Exercise 4-1
[ Posted by Urban Hafner ]
The problem
Thread semantics. Consider the following variation of the statement used in section 4.1.3 to illustrate thread semantics:
1 2 3 4 5 | |
For this exercise, do the following:
(a) Enumerate all possible executions of this statement.
(b) Some of these executions cause the program to terminate abnormally. Make a small change to the program to avoid these abnormal terminations.
My solution
(a) Line 4 has to wait until B becomes bound, so either line 2 or 3 has to execute first. The following combinations are possible:
- 2,3,4
- 2,4,3
- 3,2,4
- 3,4,2
(b) Actually all executions terminate abnormally because all of the eventually try to unify true and false. So what we have to check in the thread in line 2 and 3 is if B is already bound. This leads to the following program:
local B in
thread if {IsDet B} then skip else B=true end end
thread if {IsDet B} then skip else B=false end end
if B then {Browse yes} end
end
