[Haskell-cafe] Re: Thread pool in GHC

genneth genneth at gmail.com
Tue Sep 6 05:09:39 EDT 2005


Yes, but AFAIK, threads in Haskell are exceedingly lightweight, as
they are only primitives for concurrency. To be perfectly honest, I've
found that my solution is completely useless in practise. I made up
the solution cos I reconned that tweaking GHC runtime heap size would
be harder than making a threadpool (it isn't). Basically, all the
usual reasons for using a threadpool just don't apply in Haskell.

Gen

On 9/6/05, Dinh Tien Tuan Anh <tuananhbirm at hotmail.com> wrote:
> 
> Does it mean that the thread pool will "LAUNCH" new thread as long as the
> thread count does not exceed a maximum number ?
> If it does launch the new thread, then the idea of thread reuse is
> completely ignored.
> My program creates and kills at most 5 threads at a time, but this process
> repeated for an infinite times, so thread reuse would improve the
> performance by getting of the overhead of creating new thread.
> 
> TuanAnh
> 
> >From: genneth <genneth at gmail.com>
> >To: Dinh Tien Tuan Anh <tuananhbirm at hotmail.com>
> >CC: haskell-cafe at haskell.org
> >Subject: Re: [Haskell-cafe] Re: Thread pool in GHC
> >Date: Tue, 6 Sep 2005 10:25:15 +0800
> >
> >I think it would go back to the pool. The finally clause means that
> >even if the thread dies from an exception (which, AFAIK, is how kills
> >are modelled), the thread count would be restored.
> >
> >Gen
> >
> >On 9/6/05, Dinh Tien Tuan Anh <tuananhbirm at hotmail.com> wrote:
> > >
> > > Its probably too long to bring back this topic, but i have a small
> >question.
> > >
> > > If some threads may never terminate and have to be killed by killThread,
> >are
> > > they going back to the pool, or we need some twist to force them.
> > >
> > > Thanks a lot
> > > TuanAnh
> > >
> > > >From: genneth <genneth at gmail.com>
> > > >To: haskell-cafe at haskell.org
> > > >Subject: [Haskell-cafe] Re: Thread pool in GHC
> > > >Date: Thu, 4 Aug 2005 16:47:56 +0000 (UTC)
> > > >
> > > >Dinh Tien Tuan Anh <tuananhbirm <at> hotmail.com> writes:
> > > >
> > > > >
> > > > >
> > > > >   Can thread pool be implemented in GHC ?
> > > > >
> > > > > I have a program that is currently using about 12-15 threads (launch
> >and
> > > > > kill for infinite times) and when running, especially after Ctrl-C,
> >my
> > > > > computer got freezed up. And if i ran it several times, the "Stack
> > > > > overflows" occurs.
> > > >
> > > >I made the following a while back. Maybe it's useful...
> > > >
> > > >limitedThreadsWithChannelMapM :: Integer -> (a -> IO b) -> [a] -> IO
> >[MVar
> > > >b]
> > > >limitedThreadsWithChannelMapM lim ioaction x = do
> > > >     threadpoolcounter <- atomically ( newTVar 0 )
> > > >     mapM (throttledFork threadpoolcounter . ioaction) x
> > > >     where
> > > >         throttledFork poolcount io = do
> > > >             atomically ( do
> > > >                 prev <- readTVar poolcount
> > > >                 if prev >= lim then
> > > >                     retry
> > > >                     else writeTVar poolcount (prev+1) )
> > > >             mvar <- newEmptyMVar
> > > >             forkIO(
> > > >                 finally
> > > >                     (io >>= putMVar mvar)
> > > >                     (atomically ( readTVar poolcount >>= writeTVar
> > > >poolcount .
> > > >(subtract 1) ) ) )
> > > >             return mvar
> > > >
> > > > >
> > > > > Cheers
> > > > > TuanAnh
> > > > >
> > > > > _________________________________________________________________
> > > > > Winks & nudges are here - download MSN Messenger 7.0 today!
> > > > > http://messenger.msn.co.uk
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > >_______________________________________________
> > > >Haskell-Cafe mailing list
> > > >Haskell-Cafe at haskell.org
> > > >http://www.haskell.org/mailman/listinfo/haskell-cafe
> > >
> > > _________________________________________________________________
> > > Winks & nudges are here - download MSN Messenger 7.0 today!
> > > http://messenger.msn.co.uk
> > >
> > >
> 
> _________________________________________________________________
> It's fast, it's easy and it's free. Get MSN Messenger 7.0 today!
> http://messenger.msn.co.uk
> 
>


More information about the Haskell-Cafe mailing list