Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mailbox-empty-p for sbcl, add simple.lisp example #3

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
5 changes: 4 additions & 1 deletion mpcompat/mp-compat-sbcl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ A null timeout means wait forever."
(defun mailbox-empty? (mbox)
"Check if the Lisp mailbox is empty. Return generalized T/F."
(sb-concurrency:mailbox-empty-p mbox))


(defun mailbox-empty-p (mbox)
(mailbox-empty? mbox))


;; --------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion useful-macros/com.ral.useful-macros.asd
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ THE SOFTWARE.
#+:LISPWORKS (:file "safe-streams")
#+:LISPWORKS (:file "safe-read-patch")
(:file "safe-read-from-string")
#+:LISPWORKS (:file "objc")
#+(AND :LISPWORKS :MACOSX) (:file "objc")

#+:LISPWORKS (:file "my-complete-symbol") ;; fix problem in LW for hierarchical package support

Expand Down
4 changes: 2 additions & 2 deletions useful-macros/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,8 @@ THE SOFTWARE.
#:merge-plist
#:string-interp

#:st-to-objc
#:objc-invoke-st
#+(AND :LISPWORKS :MACOSX) #:st-to-objc
#+(AND :LISPWORKS :MACOSX) #:objc-invoke-st

#:with-unique-names
#:rebinding
Expand Down
26 changes: 26 additions & 0 deletions xTActors/Examples/simple.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;; Very simple example on how to use actors

(defpackage #:simple
(:use :common-lisp)
(:export
#:echo
#:receiver
#:run
))

(in-package #:simple)


(defparameter receiver
(actors:create
(lambda (msg)
(print (format nil "~a: ~a~%" :receiver msg)))))

(defparameter echo
(actors:create
(lambda (msg)
(print (format nil "~a: ~a~%" :echo msg))
(actors:send receiver msg))))

(defun run ()
(actors:send echo :hello))
34 changes: 34 additions & 0 deletions xTActors/Examples/stresstest.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
;; Computationally heavy usage of actors. All CPUs are used.

(defpackage #:stresstest
(:use :common-lisp)
(:export
#:echo
#:receiver
#:run
))

(in-package #:stresstest)

(defparameter *large-number* 1000000000)

(defparameter receiver
(actors:create
(lambda (idx msg)
(format t "idx: ~a, msg: ~a~%" idx msg))))

(defun create-worker ()
(actors:create
(lambda (idx cnt)
(let ((answer (loop for i from 1 to cnt count (oddp i))))
(actors:send receiver idx answer)))))

(defparameter main
(actors:create
(lambda (idx cnt)
(let ((worker (create-worker)))
(actors:send worker idx cnt)))))

(defun run ()
(dotimes (n 20)
(actors:send main n *large-number*)))
8 changes: 8 additions & 0 deletions xTActors/actors-base/macros.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,11 @@
(editor:setup-indent "α" 1)
(editor:indent-like "β" 'destructuring-bind))

;; --------------------------------------------------

(defmacro yield (&body body)
;; exit Actor to allow concurrent actions, then resume
;; forces our continuation to the back of the event queue.
`(β _
(send β)
,@body))
1 change: 1 addition & 0 deletions xTActors/actors-base/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ THE SOFTWARE.
#:splay
#:watchdog-timer
#:safe-serializer
#:yield
))

#+(OR :ALLEGRO :CCL)
Expand Down
15 changes: 4 additions & 11 deletions xTActors/actors-extra/transactional-db.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@

(defpackage com.ral.actors.kv-database
(:use #:cl :com.ral.actors)
(:local-nicknames
(#:um #:com.ral.useful-macros)
(#:uuid #:com.ral.uuid)
(#:loenc #:com.ral.lisp-object-encoder)
(#:self-sync #:com.ral.self-sync)
(#:sets #:com.ral.rb-trees.sets)
(#:maps #:com.ral.rb-trees.maps))
(:export
#:kvdb
))
Expand All @@ -116,7 +109,7 @@

;; -------------------
;; commit after update
((cust :commit old-db new-db retry)
(( (cust . retry) :commit old-db new-db)
(cond ((eql old-db db) ;; make sure we have correct version
(cond ((eql new-db db)
;; no real change
Expand Down Expand Up @@ -303,7 +296,7 @@
(defun add-rec (cust key val)
(loenc:encode (list key val)) ;; this will barf if either key or val is non-externalizable
(with-db db
(send dbmgr cust :commit db (maps:add db key val) self)
(send dbmgr `(,cust . ,self) :commit db (maps:add db key val))
))

(defun remove-rec (cust key)
Expand All @@ -312,7 +305,7 @@
(new-db (if (eql val self)
db
(maps:remove db key))))
(send dbmgr cust :commit db new-db self)
(send dbmgr `(,cust . ,self) :commit db new-db)
)))

(defun lookup (cust key &optional default)
Expand Down Expand Up @@ -345,7 +338,7 @@
((cust :req)
(repeat-send dbmgr))

((cust :commit old-db new-db retry)
(( (cust . retry) :commit old-db new-db)
(repeat-send dbmgr))
)))

Expand Down
Loading