Skip to content
The actor model implemented with closures.
Branch: master
Clone or download
Latest commit 1a0dd05 Apr 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Add LICENSE Apr 18, 2019
README.md Write a readmme. Apr 13, 2019
actors.lisp Use bt:thread instead of sb-thread:thread. Apr 2, 2019
better-handler-case.lisp Remove unnecessary code. Apr 2, 2019
ipc.lisp Revert "Remove the type constraint on a mailbox's mutex since it does… Apr 8, 2019
simple-actors.asd License. Apr 2, 2019

README.md

simple-actors

The actor model implemented with closures.

Creating an actor

CL-USER> (defvar *result* nil)
*RESULT*
CL-USER> (defparameter *actor* (simple-actors:actor (&rest numbers)
				  (setf *result*
					(loop for n in numbers
					   collect (* n 2)))))
*ACTOR*
CL-USER> *actor*
#<SIMPLE-ACTORS:ACTOR {10069D2963}>

Actors can be sent messages that match their lambda-list. These messages go into a queue, and the actor's body is evaluated with each message in order:

CL-USER> (simple-actors:send *actor* 1 2 3 4 5 6)
NIL
CL-USER> *result*
(2 4 6 8 10 12)

Each actor has a thread associated with it:

CL-USER> (bt:all-threads)
(#<SB-THREAD:THREAD "Actor" RUNNING {1006919D53}>
 #<SB-THREAD:THREAD "finalizer" RUNNING {1001B80053}>
 #<SB-THREAD:THREAD "repl-thread" RUNNING {100250FF93}>
 #<SB-THREAD:THREAD "auto-flush-thread" RUNNING {100250FDA3}>
 #<SB-THREAD:THREAD "swank-indentation-cache-thread" RUNNING {1004458183}>
 #<SB-THREAD:THREAD "reader-thread" RUNNING {1004458083}>
 #<SB-THREAD:THREAD "control-thread" RUNNING {1004450D73}>
 #<SB-THREAD:THREAD "Swank Sentinel" RUNNING {1004164873}>
 #<SB-THREAD:THREAD "main thread" RUNNING {10005E8203}>)

The actor's thread terminates when it is sent the simple-actors:stop message. This message is not passed to the actor's body.

CL-USER> (simple-actors:send *actor* 'simple-actors:stop)
NIL
CL-USER> (bt:all-threads)
(#<SB-THREAD:THREAD "finalizer" RUNNING {1001B80053}>
 #<SB-THREAD:THREAD "repl-thread" RUNNING {100250FF93}>
 #<SB-THREAD:THREAD "auto-flush-thread" RUNNING {100250FDA3}>
 #<SB-THREAD:THREAD "swank-indentation-cache-thread" RUNNING {1004458183}>
 #<SB-THREAD:THREAD "reader-thread" RUNNING {1004458083}>
 #<SB-THREAD:THREAD "control-thread" RUNNING {1004450D73}>
 #<SB-THREAD:THREAD "Swank Sentinel" RUNNING {1004164873}>
 #<SB-THREAD:THREAD "main thread" RUNNING {10005E8203}>)
You can’t perform that action at this time.