CTM: Exercise 4-4
[ Posted by Urban Hafner ]
The problem
Order-determining concurrency. Explain what happens when executing the following:
declare A B C D in
thread B=C+1 end
thread C=B+1 end
thread A=1 end
thread B=A+1 end
{Browse D}In what order are the threads created? In what order are the additions done? What is the final result? Compare with the following:
declare A B C D in
A=1
B=A+1
C=B+1
D=C+1
{Browse D}Here there is only one thread. In what order are the additions done? What is the final result? What do you conclude?
My solution
Of course both code snippets produce the same result, namely 4. And of course the threads in the first code example are executed in the same way as in the second. That’s because the threads have to wait for the variables they are using in the additions to become bound.
An what do I conclude? Well, that this kind of concurrency is declarative. At least that’s what I think I was supposed to answer :)

