- Up - | Next >> |
A new concurrent thread in Oz is created by using the expression of the form thread ... end
. For instance, during the execution of the following program two threads proceed concurrently:
declare
X {Browse X}
thread {Wait X} end
X = 1
Synchronization of threads is supported in Oz on the basis of logic variables. This is illustrated by the following program whose execution again needs two threads (compare chapter 8 of Seif Haridi's tutorial on Oz which you can find at http://mozart.ps.uni-sb.de/documentation/tutorial/node8.html#chapter.concurrency).
declare X0 X1 X2 X3 in
{Browse [X0 X1 X2 X3]}
thread
local Y0 Y1 Y2 Y3 in
{Browse [Y0 Y1 Y2 Y3]}
Y0 = X0+1
Y1 = X1+Y0
Y2 = X2+Y1
Y3 = X3+Y2
{Browse completed}
end
end
X0 = 0
X1 = 1
X2 = 2
X3 = 3
If you would like to observe the two threads in the execution you might be willing to use the Oz-debugger called Oscar which is available form the Mozart user interface (below the menue entry Oz).
- Up - | Next >> |