[HOpenGL] concurrency problem?

Sven Panne Sven_Panne@BetaResearch.de
Fri, 01 Feb 2002 09:03:08 +0100


Andre W B Furtado wrote:
> If the display callback can modify an IORef, and if the keyboard callback
> can modify the same IORef, am I expected to have concurrency problems? [...]

Well, it depends on your definition of "problem". :-) IORefs are basically
simple (mutable) variables as you know them from imperative languages, and
readIORef/writeIORef boil down to a simple memory access (see readMutVarzh
and friends in:

   http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/includes/PrimOps.h?rev=1.90&content-type=text/x-cvsweb-markup

So you get the usual behaviour when you do an unsynchronized access. But for
the case of GLUT, there is no real concurrency, as you can see from the bottom
of:

   http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/mesa3d/Mesa/src-glut/glut_event.c?rev=1.5&content-type=text/vnd.viewcvs-markup

It is the usual "get-the-next-event-and-dispatch"-approach, which is sufficient
for a simple toolkit like GLUT.

For "real" concurrency in Haskell one should better use:

   http://haskell.org/ghc/docs/latest/set/sec-concurrency-abstractions.html

Cheers,
   S.