Actually these days it's quite easy. If you have a function that acts as a handler for, say, a url request and can be invoked in different threads all you need to do is:
All threads share a single, open store-controller object. Each transaction is started and committed/aborted in the same thread.The first one is easy, just use a global variable and open the store controller when the program starts up:
(defvar *my-db-spec* '(:BDB "/user/me/db/")) (defvar *my-db-store* nil) (defun startup () (setf *my-db-store* (open-store *my-db-spec*))) Then a good policy to avoid transactions across threads is: 1) Always use with-transaction2) Never spawn a thread from within the dynamic extent of the with- transaction body form(s)
Pretty simple!I'm sorry we don't have a good canned example, however I've attached a hutchentoot-based blog example that is current and that I believe would run fine in multiple threads, although I haven't tested it.
Regards, Ian
hunchentoot.blog.lisp
Description: Binary data
On May 16, 2007, at 4:27 AM, Dmitry V. Gorbatovsky wrote:
Hello and thanks for glorious project. I would like to ask for very short (few lines) example of using 'elephant' in multiple threads on sbcl/linux. Or maybe just link to where I may find one. Beforehand gratefull. Dmitry _______________________________________________ elephant-devel site list elephant-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/elephant-devel
_______________________________________________ elephant-devel site list elephant-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/elephant-devel