[elephant-devel] multithreading
Ian Eslick
eslick at csail.mit.edu
Wed May 16 21:38:18 UTC 2007
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-transaction
2) 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hunchentoot.blog.lisp
Type: application/octet-stream
Size: 8770 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/elephant-devel/attachments/20070516/420ce0ee/attachment.obj>
-------------- next part --------------
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 at common-lisp.net
> http://common-lisp.net/mailman/listinfo/elephant-devel
More information about the elephant-devel
mailing list