25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>VDM</strong>-<strong>10</strong> <strong>Language</strong> <strong>Manual</strong><br />

16.2 Procedural Thread Definitions<br />

A procedural thread provides a mechanism to explicitly define the external behaviour of an active<br />

object through the use of statements, which are executed when the object is started (see section<br />

13.14).<br />

Syntax: procedural thread definition = statement ;<br />

Semantics: A procedural thread is scheduled for execution following the application of a start<br />

statement to the object owning the thread. The statements in the thread are then executed<br />

sequentially, and when execution of the statements is complete, the thread dies. Synchronization<br />

between multiple threads is achieved using permission predicates on shared objects.<br />

Examples: The example below demonstrates procedural threads by using them to compute the<br />

factorial of a given integer concurrently.<br />

✞<br />

class Factorial<br />

instance variables<br />

result : nat := 5;<br />

operations<br />

public factorial : nat ==> nat<br />

factorial(n) ==<br />

if n = 0<br />

then return 1<br />

else (dcl m : Multiplier;<br />

m := new Multiplier();<br />

m.calculate(1,n);<br />

start(m);<br />

result:= m.giveResult();<br />

return result<br />

)<br />

end Factorial<br />

class Multiplier<br />

instance variables<br />

i : nat1;<br />

j : nat1;<br />

k : nat1;<br />

result : nat1<br />

148

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!