[Haskell-cafe] GUI and background processing
akamaus at gmail.com
Mon Jun 1 08:24:36 EDT 2009
Greetings, fellow haskellers.
Currently I'm writing some kind of web crawler in haskell with gtk2hs gui.
All network operations are run in separate thread, but sometimes input
from user is needed. Afaik, gtk2hs is not thread safe, so I came up with
I create two mvars, A and B, one for question, one for answer. Worker
thread puts question in A and blocks trying to take B. Gui thread checks
for question by polling with tryTakeMVar. Then question is ready, it
asks user and puts his answer into B. Worker awakens and continues
Also, for progress report, I use a Chan which is written to by worker
and is read by polling by gui thread.
This scheme works, but I don't like it. All these mvars and chans create
too much clutter, and polling looks rather ugly too. Is there a better
way for implementing similar patterns of interaction?
More information about the Haskell-Cafe