[Haskell-beginners] Threading (lack of) interleaving

Chris Schneider chris at christopher-schneider.com
Mon Aug 5 06:05:47 CEST 2013

Hi, I'm working on a program that should launch, spawn two threads, each
with a zeromq connection, where those threads ping the zmq channel
repeatedly.  The main thread just sits and waits.

The code is here: https://gist.github.com/cschneid/3862b33c29a803be7848

If I launch one thread, or the other (lines 13 & 14), and comment the other
one out, it runs as expected.

But if I attempt to launch both, both build themselves, and run one call of
themselves, but then it seems that one or the other thread "wins", and the
other never gets to run again.  Most of the time it's the first one
launched that wins, but not always.  See the output for an example.

Adding explicit yield calls, using forkOS vs forkIO, and moving around of
where I make the ZMQ context & socket (into and out of the threads) don't
seem to help.

What am I missing?  How can I get these threads to play nice with each

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130804/cb5c86c9/attachment.htm>

More information about the Beginners mailing list