Concurrent

Multi-Process library

Summary
ConcurrentMulti-Process library
(mosh concurrent)Multi-Process Library.
Functions
spawnCreate a process which executes proc.
spawn-linkspawn and link.
process-exitexit process with status.
!Send a message object to pid process.
linkLink self and other process.
unlinkunlink linked process
selfReturns self pid.
receiveReceive a message which matches <match clause>.
join!Waits termination of process.
registerRegister a process by name.
whereisLook up process by name
make-process-errorMake a process-error
process-error?Returns #t if obj is process-error condition, otherwise #f.
process-errorReturns error state of process-error condition.
sleepsleep n msec.

(mosh concurrent)

Multi-Process Library.

N.B.  If you share R6RS records between multiple processs, define them as nongenerative.

Summary
Functions
spawnCreate a process which executes proc.
spawn-linkspawn and link.
process-exitexit process with status.
!Send a message object to pid process.
linkLink self and other process.
unlinkunlink linked process
selfReturns self pid.
receiveReceive a message which matches <match clause>.
join!Waits termination of process.
registerRegister a process by name.
whereisLook up process by name
make-process-errorMake a process-error
process-error?Returns #t if obj is process-error condition, otherwise #f.
process-errorReturns error state of process-error condition.
sleepsleep n msec.

Functions

spawn

Create a process which executes proc.  On Mosh, a process means an independent VM instance.  The process which is spawn-ed and calls spawn share nothing.  Each processes has own independent namespace.

Prototype

(spawn proc-expr arg import-spec)

Parameters

proc-expr(lambda (arg) ...) expression to execute.
argargument for proc-expr.
import-specimport spec.

Example

(spawn (lambda (x) (display x)) 'hello '((rnrs)))

Returns

pid

spawn-link

spawn and link.

Prototype

(spawn-link proc-expr arg import-spec)

Parameters

proc-expr(lambda (arg) ...) expression to execute.
argargument for proc-expr.
import-specimport spec.

Returns

pid

process-exit

exit process with status. status is sent to linked process as ‘(exit status) message.

Prototype

(process-exit status)

!

Send a message object to pid process.  ! procedure will not be blocked, returns immediately.

Prototype

(! pid obj)

link

Link self and other process.  Linked processes send ‘(exit why) message when exit to each other.

Prototype

(link pid)

Parameters

pidpid of process

unlink

unlink linked process

Prototype

(unlink pid)

Parameters

pidpid of process

self

Returns self pid.

Prototype

(self)

Returns

pid

receive

Receive a message which matches <match clause>.  If there is no message or no matched message, receive is blocked.  <match clause> may have [after timeout ...], receive wait timeout msec and returns

Prototype

(receive <match clause> ...)

Example

;; wait and receive ('exit why) message.
(receive
  [('exit why)
    (display why)])

;; wait two pattern messages.
(receive
  [('exit why)
    (display why)]
  [x
    (display "unknown message")
    (display x)])

;; wait with timeout
(receive
  [('exit why)
    (display why)]
  [after 1000
    (display "exit why doesn't come in 1000 msec")])

join!

Waits termination of process.

Prototype

(join! pid)

Parameters

pidpid of process.

Example

(let ([pid (spawn (lambda (x) (display x)) 'hello '((rnrs)))])
   (join! pid))

register

Register a process by name.  Registered process can be fetch with whereis procedure by name.

Prototype

(register name pid)

Parameters

namename to register
pidpid of process

whereis

Look up process by name

Prototype

(whereis name)

Parameters

namename to look up

Returns

pid of found process or #f

make-process-error

Make a process-error

Prototype

(make-process-error state)

Parameters

stateerror state

Returns

process-error condition

process-error?

Returns #t if obj is process-error condition, otherwise #f.

Prototype

(process-error? obj)

Returns

#t if obj is process-error condition, otherwise #f.

process-error

Returns error state of process-error condition.

Prototype

(process-error process-error-condition)

Returns

Returns error state of process-error condition.

sleep

sleep n msec.

Prototype

(sleep n)
Close