From: David Bakhash
Subject: Servers in Lisp...
Date: 
Message-ID: <cxjr9mq3gr1.fsf@acs5.bu.edu>
Hi,

I'm writing a server in which I want at most N threads running
simultaneously.  The server is a request broker that gets requests and just
hands it off to one of N real servers.  So the concept is simple:

have a Q of requests, and send route them to the N servers first-come
first-serve.

So I figure that I'll have a pool (set (list) in Lisp) of streams to
_available_ servers, not currently being used.  I'll have a Q of clients
waiting for results.  

The question is as follows.  I want a thread to `listen' to a data structure
(a simple list, the pool of open streams to actual servers) waiting to get
one.  Then, I want it to `listen' again to the clients (a queue, in this case)
waiting until it's not empty, and only then starting a new thread.  I need to
use the MP package in such a way so as that the thread waiting on the queue
and pool can be somehow "asynchronous".  Really, what I want is for the thread
which is waiting on the non-empty pool/queue to sleep nicely between
consecutive polls, if necessary.  I don't know enough about how threads work
to know how to do this right.

using the MP package, I see a function called `mp:process-allow-scheduling',
and that might be a possibility, i.e. if it is placed at the end of a polling
loop.  But I'd like some expert advice.

thanks,
dave