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.

Chapter 6. Expressions<br />

Examples: Using threadid’s it is possible to provide a <strong>VDM</strong>++ base class that implements a Javastyle<br />

wait-notify in <strong>VDM</strong>++ using permission predicates. Any object that should be available<br />

for the wait-notify mechanism must derive from this base class.<br />

✞<br />

class WaitNotify<br />

instance variables<br />

waitset : set of nat := {};<br />

operations<br />

protected wait: () ==> ()<br />

wait() ==<br />

let p = threadid<br />

in (<br />

AddToWaitSet( p );<br />

Awake();<br />

);<br />

AddToWaitSet : nat ==> ()<br />

AddToWaitSet( p ) ==<br />

waitset := waitset union { p };<br />

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

Awake() ==<br />

skip;<br />

protected notify: () ==> ()<br />

notify() ==<br />

if waitset {}<br />

then let arbitrary_process in set waitset<br />

in waitset := waitset \ {arbitrary_process};<br />

protected notifyAll: () ==> ()<br />

notifyAll() ==<br />

waitset := {};<br />

sync<br />

mutex(notifyAll, AddToWaitSet, notify);<br />

per Awake => threadid not in set waitset;<br />

end WaitNotify<br />

✡✝<br />

✆<br />

61

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

Saved successfully!

Ooh no, something went wrong!