Minerva supports timer handling....
Move to
Next Prev
Up Top
Zoom to
timer_close/1
timer_create/2
timer_is_active/1
timer_start/2
timer_stop/1
See also
Arithmetic comparison
Arithmetic evaluation
Atomic term processing
Text Processing and Regular Expressions
Blackboards
BinaryIO
Character input/output
Constraints
Compilation
Clause creation and destruction
Clause retrieval and information
global variables
Grammar rules
Lists
Logic and control
All Solutions
Communication between distributed Minerva processes.
Stream selection and control
Servlet
Term comparison
Term creation and decomposition
Term input/output
Term unification
Term vector
Term Stream
XML (eXtended Markup Language) terms
Asynchronous timer handling
Type testing
IF Computer > MINERVA > Manual > Reference > Predicates > Asynchronous timer handling

Asynchronous timer handling

Minerva supports timer handling.

There exist a small set of predicates to support timer handling.

  • timer_create/2
  • timer_close/2
  • timer_start/2
  • timer_stop/1
  • timer_is_active/1

A timer can be created, deleted, started, stopped and the state of a timer (running or not running) can be checked. There is a user defined callback predicate, that can be bound to a timer. When a timer runs down, then this callback predicate will be called. Each timer is implemented as a thread. So timer callbacks may be fired asynchronously. However, there is no multithreading support in Minerva, that is: at any time Minerva can only execute one goal. Only when the execution of one goal has been finished another goal (maybe called from another thread) may be executed.

Therefore, if you need timer support, then your program should have the following structure:

main(..) :-
    ...
    timer_create(mycallback(_,...), Timer),
    ...
    timer_start(Timer, T).

mycallback(Timer, ...) :- ...

When executing your program you have to call Minerva with the program flag -daemon. This prevents, that Minerva stops execution when the main/1 predicate has been executed. Minerva will only be stopped when all of his threads have been stopped.

Example

main(_) :- ticker.

ticker :- set_global(ticker, 10), % create a timer, that should call tick/1 when running down timer_create(tick(_), Timer), % start the timer ... timer_start(Timer, 1000). % ... and (very important!!) ... stop the execution of main/1

tick(Timer) :- count_down(ticker, N), ( N > 0 -> % write 'tick' ... write(tick), nl, % .. and restart the timer ... timer_start(Timer, 1000) % ... and (very important!!) ... stop the execution of tick/1 % as the execution of the callback predicate will be pending % until the execution of tick/1 has been finished ; timer_close(Timer) ).

count_down(Counter, Value) :- get_global(Counter, OldValue), Value is OldValue - 1, set_global(Counter, Value).

read on...
timer_close/1
Stops a timer and deletes it...
timer_create/2
Creates a timer and binds a callback predicate to it....
timer_is_active/1
Checks the state of a timer...
timer_start/2
Starts a timer...
timer_stop/1
Stops a timer...
MINERVA
ifcomputer logo
f
Expert Services on the Web
Language
English
Japanese
Server
USA
Japan
Site Access
Local Index
Local Contents
Site Contents
Site Index
Printer Friendly
For imode
For PDA
Search
document: http://www.ifcomputer.co.jp/MINERVA/Manual/Reference/Predicates/timer/home_en.html
published 2012/1/30 update 2002/3/20 (c) 1996-2009 IF Computer Japan
IF Computer 5-28-2 Sendagi, Bunkyo-ku Tel +81-3-5814-3352 start (AT) ifcomputer.com
Customer Support Tokyo 113-0022 Japan   http://www.ifcomputer.com
scroll to top managed with ubiCMS