[Haskell-cafe] Question about concurrency, threads and GC

Gregory Collins greg at gregorycollins.net
Sat Mar 3 10:38:16 CET 2012


On Fri, Mar 2, 2012 at 5:19 PM, Paul Graphov <graphov at gmail.com> wrote:

> Hello Cafe!
>
> I am trying to implement networked application in Haskell. It should
> accept many
> client connections and support bidirectional conversation, that is not
> just loop with
> Request -> Response function but also sending notifications to clients etc.
>

Hi,

The tutorial I gave for CUFP 2011 was a multi-user web chat program using
the Snap Framework. STM channels make this kind of problem super-easy to
deal with. Don't be afraid of forking lots of Haskell threads for programs
like this, because they're "green" threads, not OS threads (i.e. Haskell
threads are M:N multiplexed onto OS threads) and as such they have very
little overhead.

Maybe you'll find the code interesting:
https://github.com/snapframework/cufp2011. The "business logic" of using
STM channels is here:
https://github.com/snapframework/cufp2011/blob/master/src/Snap/Chat/ChatRoom.hs

G
-- 
Gregory Collins <greg at gregorycollins.net>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120303/6bae6aa1/attachment.htm>


More information about the Haskell-Cafe mailing list