kill-periodic-functionScheduled and Periodic Functionspause-scheduled-function-schedulermake-scheduled-functionGoTo Top

make-scheduled-function   function &key name name-test marker marker-test context => scheduled-function[Function]

Purpose
Create a scheduled function.

Package   :portable-threads

Module   :portable-threads

Arguments and values

function     A function designator specifying a function object of one argument
name     An object (typically a string or a symbol; default is function, if function is a symbol, otherwise nil)
name-test     A function designator specifying a function object of two arguments that returns a generalized boolean (default is #'eql)
marker     An object (default is nil)
marker-test     A function designator specifying a function object of two arguments that returns a generalized boolean (default is #'eql)
context     An object (default is nil)
scheduled-function     A scheduled function

Returns
The newly created scheduled function.

Errors
Threads (multiprocessing) is not supported on the Common Lisp implementation.

Description
Unless the run time to perform the scheduled function is brief, it should spawn a new thread in which to perform its activities so as to avoid delaying the invocation of a subsequent scheduled function.

The optional marker and associated comparison marker-test can be specified to distinguish scheduled functions with the same name in calls to schedule-function, schedule-function-relative, and unschedule-function.

The optional context object can be specified to store an invocation context in the scheduled-function object that is passed to the scheduled function when it is invoked.

See also
    *schedule-function-verbose*
    all-scheduled-functions
    pause-scheduled-function-scheduler
    restart-scheduled-function-scheduler
    resume-scheduled-function-scheduler
    schedule-function
    schedule-function-relative
    scheduled-function-context
    scheduled-function-invocation-time
    scheduled-function-marker
    scheduled-function-marker-test
    scheduled-function-name
    scheduled-function-name-test
    scheduled-function-repeat-interval
    scheduled-function-scheduler-paused-p
    scheduled-function-scheduler-running-p
    spawn-periodic-function
    unschedule-function

Examples
Create a scheduled function that simply prints "Hello" when invoked:

  > (make-scheduled-function 
      #'(lambda (scheduled-function)
          (declare (ignore scheduled-function))
          (print "Hello"))
      :name 'hello)
  #<scheduled-function hello [unscheduled]>
  >
Create a scheduled function that individualizes the "Hello" when invoked:
  > (make-scheduled-function 
      #'(lambda (scheduled-function)
          (format t "~&Hello ~a~%" 
            (scheduled-function-context scheduled-function)))
      :name 'hello
      :context "Bob")
  #<scheduled-function hello [unscheduled]>
  >

A more complex scheduled function that spawns a new thread to do its work and randomly sets whether to reschedule itself (and at what interval):

  > (defun complex-function (scheduled-function)
      (let ((interval (random 100)))
        (setf (scheduled-function-repeat-interval scheduled-function)
              (if (plusp interval) 
                  ;; repeat 1-99 seconds from now:
                  interval
                  ;; don't repeat 1% of the time:
                  nil)))
      (spawn-thread "Lots of stuff doer" #'do-lots-of-stuff))
  complex-function
  > (make-scheduled-function 'complex-function)
  #<scheduled-function complex-function [unscheduled]>
  >


The GBBopen Project


kill-periodic-functionScheduled and Periodic Functionspause-scheduled-function-schedulermake-scheduled-functionGoTo Top