25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 16. Threads (<strong>VDM</strong>++ and <strong>VDM</strong>-RT)<br />

The Timer has two instance variables the current time and a flag indicating whether the Timer<br />

is active or not (the current time is only incremented if the Timer is active).<br />

✞<br />

instance variables<br />

curTime : nat := 0;<br />

active : bool := false;<br />

✡✝<br />

✆<br />

The Timer provides straightforward operations which need no further explanation.<br />

✞<br />

operations<br />

public Start : () ==> ()<br />

Start() ==<br />

(active := true;<br />

curTime := 0);<br />

public Stop : () ==> ()<br />

Stop() ==<br />

active := false;<br />

public GetTime : () ==> nat<br />

GetTime() ==<br />

return curTime;<br />

✡✝<br />

IncTime: () ==> ()<br />

IncTime() ==<br />

if active<br />

then curTime := curTime + <strong>10</strong>0;<br />

✆<br />

The Timer’s thread ensures that the current time is incremented. The period with which<br />

this is done is <strong>10</strong>00 time units. The allowed jitter is <strong>10</strong> time units and the minimal distance<br />

between two instances is 200 time units and finally no offset has been used.<br />

✞<br />

thread<br />

periodic(<strong>10</strong>00,<strong>10</strong>,200,0)(IncTime)<br />

end Timer<br />

✡✝<br />

✆<br />

147

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

Saved successfully!

Ooh no, something went wrong!