16 Time and alarm library
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog C-library
        • Time and alarm library
          • alarm/4
          • alarm/3
          • alarm_at/4
          • install_alarm/1
          • install_alarm/2
          • uninstall_alarm/1
          • remove_alarm/1
          • current_alarm/4
          • call_with_time_limit/2
Availability::- use_module(library(time)).(can be autoloaded)
alarm(+Time, :Callable, -Id, +Options)
Schedule Callable to be called Time seconds from now. Time is a number (integer or float). Callable is called on the next pass through a call- or redo-port of the Prolog engine, or a call to the PL_handle_signals() routine from SWI-Prolog. Id is unified with a reference to the timer.

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:

remove(Bool)
If true (default false), the timer is removed automatically after fireing. Otherwise it must be destroyed explicitly using remove_alarm/1.
install(Bool)
If false (default true), the timer is allocated but not scheduled for execution. It must be started later using install_alarm/1.