In some applications, agents are activated regularly at a predefined rate. For example, a clock animator is activated every second and the scheduler in a time-sharing system switches control to the next process after a certain time quota elapses. To facilitate the description of time-related behavior of agents, B-Prolog provides timers.
To create a timer, use the predicate
timer(T,Interval)
where T is a variable and Interval is an integer that specifies the rate of the timer. A timer runs as a separate thread. The call timer(T,Interval) binds T to a Prolog term that represents the thread. A timer starts ticking immediately after being created. It posts an event time(T) in every Interval milliseconds. A timer stops posting events after the call timer_stop(T). A stopped timer can be started again. A timer is destroyed after the call timer_kill(T) is executed.
- timer(T,Interval): T is a timer with the rate being set to Interval.
- timer(T): Equivalent to timer(T,200).
- timer_start(T): Start the timer T. After a timer is created, it starts ticking immediately. Therefore, it is unnecessary to start a timer with timer_start(T).
- timer_stop(T): Stop the timer.
- timer_kill(T): Kill the timer.
- timer_set_interval(T,Interval): Set the interval of the timer T to Interval. The update is destructive and the old value is not restored upon backtracking.
- timer_get_interval(T,Interval): Get the interval of the timer T.
Subsections
Neng-Fa Zhou
2012-01-03