Ian Jackson writes:

> Firstly, let me say that I'm very new to Haskell, so it may be that
> I'm just going about things in a fundamentally wrong way.
> 
> I'm writing an application in Haskell which, if I were to write it in
> C, would be an event-driven select-loop based program.  It needs to
> handle timeouts, and know when particular external (network) events
> happen.
> 
> I was pleased to see that GHC has a library misc/Select which will
> allow me to call select(2).  This will allow me to build the
> event-processing arrangements.

I'd suggest using concurrency instead of Select.  GHC's I/O subsystem is
designed such that a thread waiting on I/O doesn't halt the whole system, so
you can have several threads doing I/O simultaneously (eg. as in a
multi-threaded server model, where each client is served by an individual
thread).

You can also implement timeouts using threadDelay and asynchronous
exceptions.  I've just modified GHC to allow a thread to have more control
over the delivery of asynchronous exceptions: threads can now "block"
asynchronous exceptions during a critical section; this turned out to be
necessary for programming certain types of inter-thread communication using
exceptions.

Cheers,
        Simon

Reply via email to