Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting random state in all hunchentoot threads on ccl

38 views
Skip to first unread message

jshr...@gmail.com

unread,
Sep 22, 2017, 8:30:40 PM9/22/17
to
I'm using ccl and hunchentoot. I discovered that each thread needs to have a new random state, otherwise you get the same random sequence each time through, so now the first thing I do in my thread code is (setf *random-state* (make-random-state t)), but this seems wrong. First off, it's setting the global *random-state* every time a thread starts. Also, there should be a way to do this with some sort of :before method on the hunchentoot thread spinner, so that I don't have to do this at the head of every server. As always, your guidance appreciated!

Kaz Kylheku

unread,
Sep 22, 2017, 9:19:58 PM9/22/17
to
On 2017-09-23, jshr...@gmail.com <jshr...@gmail.com> wrote:
> I'm using ccl and hunchentoot. I discovered that each thread needs to
> have a new random state, otherwise you get the same random sequence
> each time through, so now the first thing I do in my thread code is
> (setf *random-state* (make-random-state t)), but this seems wrong.
> First off, it's setting the global *random-state* every time a thread
> starts.

The way out of that is of course:

(let ((*random-state* (make-random-state t)))
... rest of thread code...)

> Also, there should be a way to do this with some sort of
> :before method on the hunchentoot thread spinner, so that I don't have
> to do this at the head of every server. As always, your guidance
> appreciated!

Not familiar with that thread spinner, but as a general note, I think
this would have to be an :around method, so you could do, in its body,
something like:

(let ((*random-state* (make-random-state t)))
(call-next-method)) ;; the next method has the thread body.

A :before method will return before the next method is dispatched,
which will unravel any bindings it set up.

jshr...@gmail.com

unread,
Sep 22, 2017, 10:53:39 PM9/22/17
to
Yes, good points, both! (Actually, I don't know why I didn't think of let binding *random-state*, which in retrospect is totally obvious!)

Pascal J. Bourguignon

unread,
Sep 24, 2017, 1:34:25 PM9/24/17
to
bt:make-thread has an :initial-bindings keyword,
and there's bt:*default-special-bindings*:

(bt:make-thread (function your-thread-main)
:initial-bindings (acons '*random-state* (make-random-state t)
bt:*default-special-bindings*))

--
__Pascal J. Bourguignon
http://www.informatimago.com

jshr...@gmail.com

unread,
Sep 28, 2017, 12:27:18 AM9/28/17
to
Thanks, Pascal. I was hoping for something more general, so that I don't have to do this for everyone one of my thread-main fns. I guess I could go into the HT code and just look at what it does.
0 new messages