Alarm queues allow scheduling items. Items are Prolog terms and are copied. An alarm queue can be created by the predicate alarm_new/1. An alarm queue need not be explicitly destroyed, it will automatically be reclaimed by the Java GC when not anymore used. Threads waiting for an alarm queue can be interrupted.Example:
?- time_out((repeat, write('Hello World!'), nl,
thread_sleep(1000), fail), 3000).
Error: Execution aborted since time limit exceeded.
An item can be scheduled with the predicate alarm_schedue/4
giving a delay in milliseconds. The predicate alarm_next/2 allows
getting an item from a queue. The predicate will block for the
earliest item. The predicate alarm_cancel/2 will remove an item
from the queue.
The predicate time_out/2 uses a predefined alarm queue which is
served by a predefined thread. The predicate executes the given
goal once in the given timeout. When the timeout is reached before
the goal completes an exception is thrown.