LispWorks User Guide and Reference Manual > 35 The MP Package

NextPrevUpTopContentsIndex

create-simple-process

Function
Summary

Creates and returns a simple process, which is a process with no stack of its own.

Signature

create-simple-process name function wait-function &key function-arguments wait-function-arguments priority => process

Package

mp

Arguments

name

A string or symbol

function

A function

wait-function

A function

function-arguments

A list of arguments for function

wait-function-arguments

A list of arguments for wait-function

priority

A fixnum

Values

process

A simple process

Description

The create-simple-process function creates and returns a simple process, which is a process that has no stack of its own.

The name argument is a string or symbol that names the process. The function argument is a function to be run in the process, and the wait-function argument is a wait function that determines when the process function is run. The value of function-arguments is a list of arguments to which the process function is applied. The value of wait-function-arguments is a list of arguments to which the wait function is applied. The : priority argument is a fixnum that specifies a priority for the process. The default priority is the value of *default-simple-process-priority* , and is usually 0.

When the wait function, applied to the wait-function-arguments , returns a value other than nil , the process function is applied to the function-arguments. The process function is executed inside an mp:without-preemption form. If an error occurs in a simple process, that process is stopped and a continuable error is signaled in the process that was running at the time the simple process was started (or the last process to run if the system was idle). Continuing from the error restarts the simple process.

Because a simple process has no stack of its own, it can be executed on an arbitrary stack. However, simple processes have restrictions, the primary one being that they cannot block. The following interfaces cannot be used in a simple process:

Other Common Lisp functions might not work if they attempt to block. This applies in particular to I/O functions on streams such as pipes and to (setf gethash) on a hash table that another process is mapping over.

For more information, see Multiprocessing.

Example

The following example creates a simple process that prints the value of *a* to the background output when the value is other than nil . The process function then sets *a* to nil . From a listener, the value of *a* can be set to trigger the process to run once and then sleep again.

(defvar *a* 'i) *A*
(defun a ()
  (let ((a *a*))
    (setq *a* nil)
    (format mp:*background-standard-output*
                   "*a* is ~a~%" a)))
A (defun b () *a*) B (setq r (mp:create-simple-process 'test-proc 'a 'b)) #<MP::SIMPLE-PROCESS Name TEST-PROC Priority 0 State NIL>
See also

process-run-function


LispWorks User Guide and Reference Manual - 22 Dec 2009

NextPrevUpTopContentsIndex