This library is not available if SWI-Prolog is compiled without support for multiple threads.
The library(time)
provides timing and alarm functions.
Alarms are thread-specific, i.e., creating an alarm causes the alarm
goal to be called in the thread that created it. The predicate current_alarm/4
only reports alarms that are related to the calling thread. If a thread
terminates, all remaining alarms are silently removed. Most applications
use call_with_time_limit/2.
The resolution of the alarm depends on the underlying implementation, which is based on pthread_cond_timedwait() (on Windows on the pthread emulation thereof). Long-running foreign predicates that do not call PL_handle_signals() may further delay the alarm. The relation to blocking system calls (sleep, reading from slow devices, etc.) is undefined and varies between implementations.
Options is a list of Name(Value)
terms. Defined options are:
true
(default false
), the timer is removed
automatically after fireing. Otherwise it must be destroyed explicitly
using remove_alarm/1.false
(default true
), the timer is
allocated but not scheduled for execution. It must be started later
using install_alarm/1.alarm(Time, Callable, Id,[])
.install(false)
or stopped using uninstall_alarm/1.done
if the alarm has been called, next
if it
is the next to be fired and scheduled otherwise.time_limit_exceeded
. See catch/3.
Please note that this predicate uses alarm/4 and therefore its effect on long-running foreign code and system calls is undefined. Blocking I/O can be handled using the timeout option of set_stream/2 or waiting for input using wait_for_input/3.