[Haskell-cafe] GUI and background processing
Dmitry V'yal
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
following:
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
processing.
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?
Best regards,
Dmitry.
More information about the Haskell-Cafe
mailing list