-{ $description "Creates and registers an alarm to start at " { $snippet "time" } ". If " { $snippet "frequency" } " is " { $link f } ", this will be a one-time alarm, otherwise it will fire with the given frequency. The quotation will be called from the alarm thread." } ;\r
+{ $description "Creates and registers an alarm to start at " { $snippet "start" } " offset from the current time. If " { $snippet "interval" } " is " { $link f } ", this will be a one-time alarm, otherwise it will fire with the given frequency, with scheduling happening before the quotation is called in order to ensure that the next event will happen on time. The quotation will be called from the alarm thread." } ;\r
-"The " { $vocab-link "alarms" } " vocabulary provides a lightweight way to schedule one-time and recurring tasks without spawning a new thread." $nl\r
+"The " { $vocab-link "alarms" } " vocabulary provides a lightweight way to schedule one-time and recurring tasks without spawning a new thread. Alarms use " { $vocab-link "monotonic-clock" } ", so they continue to work across system clock changes." $nl\r
+! See http://factorcode.org/license.txt for BSD license.
+USING: help.markup help.syntax kernel math ;
+IN: monotonic-clock
+
+HELP: monotonic-count
+{ $values
+
+ { "n" integer }
+}
+{ $description "Returns a monotonically increasing number of nanoseconds since an arbitrary time. This number can be compared against future calls to " { $link monotonic-count } "." } ;
+
+ARTICLE: "monotonic-clock" "Monotonic clock"
+"The " { $vocab-link "monotonic-clock" } " vocabulary implements a single word which can be used as a clock. A special property of this clock is that it is independent of the system time and time zones." $nl
+"Get the number of nanoseconds since an arbitrary beginning:"
@@ -16,7+16,7 @@ ARTICLE: "threads-start/stop" "Starting and stopping threads"
}
"Threads stop either when the quotation given to " { $link spawn } " returns, or when the following word is called:"
{ $subsections stop }
-"If the image is saved and started again, all runnable threads are stopped. Vocabularies wishing to have a background thread always running should use " { $link add-init-hook } "." ;
+"If the image is saved and started again, all runnable threads are stopped. Vocabularies wishing to have a background thread always running should use " { $link add-startup-hook } "." ;
ARTICLE: "threads-yield" "Yielding and suspending threads"
{ $description "Sets the initial quotation called by the VM on startup. This quotation must begin with a call to " { $link boot } ". The image must be saved for changes to the boot quotation to take effect." }
{ $notes "The " { $link "tools.deploy" } " tool uses this word." } ;
-HELP: init-hooks
+HELP: startup-hooks
{ $var-description "An association list mapping string identifiers to quotations to be run on startup." } ;
-HELP: do-init-hooks
+HELP: shutdown-hooks
+{ $var-description "An association list mapping string identifiers to quotations to be run on shutdown." } ;
+
+HELP: do-startup-hooks
{ $description "Calls all initialization hook quotations." } ;
-HELP: add-init-hook
+HELP: do-shutdown-hooks
+{ $description "Calls all shutdown hook quotations." } ;
{ $description "Registers a startup hook. The hook will always run when Factor is started. If the hook was not already defined, this word also calls it immediately." } ;