[Haskell-cafe] Tackling IO (the correct way)

Stefan O'Rear stefanor at cox.net
Thu Aug 23 01:18:14 EDT 2007

On Thu, Aug 23, 2007 at 06:04:54AM +0100, Dave Tapley wrote:
> Now I wish to update a HOpenGL window synchronously with this.
> To establish this I make a new HOpenGL window & return an IORef (IO
> ()) which holds the actions to draw my graphics. In this fashion:
> Because neither 'mapM_ (updateFunction myIORef) fromRobot' nor
> 'mainLoop' terminate I've been using 'forkIO' to split one off. This
> way the lazy evaluation keeps running and then window keeps updating
> itself.
> This works, sort of.
> I have problems because the my HOpenGL code also has magic to allow
> you to change the point of view using the keyboard. But when I do I
> get this after a while:
>         Previous intel_span.c:210
>         Current: intel_batchbuffer.c:63
> Can anyone suggest how to resolve this "two functions which never
> terminate but both share IORefs" problem?

I don't know if this is your problem, but calling OpenGL from a thread
created using forkIO is an extremely bad idea.  forkIO does not
guarantee a one-to-one mapping between Haskell threads and OS threads
used for foreign calls, which horribly breaks broken APIs like OpenGL
that use thread local state.  Use forkOS instead for things like this.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070822/cb61e484/attachment.bin

More information about the Haskell-Cafe mailing list