[Haskell-cafe] threadDelay granularity

Ulrik Rasmussen haskell at utr.dk
Tue Apr 7 10:24:28 EDT 2009


On Tue, Apr 07, 2009 at 04:01:01PM +0200, Peter Verswyvelen wrote:
> Are you on Windows? Because this might be because GHC is not using a high
> resolution timer for doing its scheduling, I don't know...

No, Ubuntu 8.10. That may very well be, I'm not that much into the
details of GHC. 

I'm thinking about importing a system dependent delay method through the
FFI to get more control over the delay interval, but that seems like
overkill too. Also, I don't know if that would introduce some nasty
problems, again, I'm not that into the inner workings of GHC.

For now I'll just allow the application to render as fast as possible,
the primary motivation for capping the framerate was to prevent my laptop
from getting so hot that I can't have it in my lap :).

(I see that I replied to you instead of to the list by accident. I'm
CC'ing the message to the list now)

/Ulrik

> On Tue, Apr 7, 2009 at 3:21 PM, Ulrik Rasmussen <haskell at utr.dk> wrote:
> 
> > On Tue, Apr 07, 2009 at 02:53:20PM +0200, Peter Verswyvelen wrote:
> > > I think this is an RTS option.
> > >
> > http://www.haskell.org/ghc/docs/latest/html/users_guide/using-concurrent.html
> >
> > Ahh, I found it now. Seems like the `-C' option didn't work because it
> > still limited by the master tick interval. Using `+RTS -V0.001' helps.
> > It is a bit inaccurate at that resolution though.
> >
> > >
> > >
> > >
> > > On Tue, Apr 7, 2009 at 1:41 PM, Ulrik Rasmussen <haskell at utr.dk> wrote:
> > >
> > > > Hello.
> > > >
> > > > I am writing a simple game in Haskell as an exercise, and in the
> > > > rendering loop I want to cap the framerate to 60fps. I had planned to
> > do
> > > > this with GHC.Conc.threadDelay, but looking at it's documentation, I
> > > > discovered that it can only delay the thread in time spans that are
> > > > multiples of 20ms:
> > > >
> > > >
> > > >
> > http://www.haskell.org/ghc/docs/6.4/html/libraries/base/Control.Concurrent.html
> > > >
> > > > I need a much finer granularity than that, so I wondered if it is
> > > > possible to either get a higher resolution for threadDelay, or if there
> > > > is an alternative to threadDelay?
> > > >
> > > > I noticed that the SDL library includes the function "delay", which
> > > > indeed works with a resolution down to one millisecond. However, since
> > > > I'm using HOpenGL and GLUT, I think it would be a little overkill to
> > > > depend on SDL just for this :).
> > > >
> > > >
> > > > Thanks,
> > > >
> > > > Ulrik Rasmussen
> > > > _______________________________________________
> > > > Haskell-Cafe mailing list
> > > > Haskell-Cafe at haskell.org
> > > > http://www.haskell.org/mailman/listinfo/haskell-cafe
> > > >
> >


More information about the Haskell-Cafe mailing list