[Haskell-cafe] Having a very annoying problem related with (I think) lazy IO

Yuras Shumovich shumovichy at gmail.com
Fri Dec 12 16:53:15 UTC 2014


Well, I'm not sure, I just wrote what my nose suggested me. I can't
count how many times I got something similar in my own code, and each
time it was a thread that runs too fast.

I mean the `lock` at line 121 (`takeMVar lock`). I don't know whether it
is used somewhere else though. It also could be `updated` MVar, or it is
a flaw in ghc's scheduler...

You can try ThreadScope (see e.g.
https://www.haskell.org/haskellwiki/ThreadScope ) to see a difference
between two versions (with and without `putStrLn`). It is hard to
suggest anything specific without deep study.

On Fri, 2014-12-12 at 18:38 +0200, Ömer Sinan Ağacan wrote:
> Amazing, that really worked. I'm still confused about why this is
> happening though.
> 
> > it doesn't give other parts of your program to take a lock.
> 
> What lock are we talking about here?
> 
> 2014-12-12 18:33 GMT+02:00 Ömer Sinan Ağacan <omeragacan at gmail.com>:
> > Interesting, I think that worked. (I'll try on bigger examples and update again)
> >
> >> Probably the loop is too fast, and it doesn't give other parts of your
> > program to take a lock.
> >
> > Are there any ways to test for this? How do I know if this is really the case?
> >
> > 2014-12-12 18:20 GMT+02:00 Yuras Shumovich <shumovichy at gmail.com>:
> >> What if you replace the `putStrLn` with `yield` or `threadDelay 1`?
> >> Probably the loop is too fast, and it doesn't give other parts of your
> >> program to take a lock.
> >>
> >> On Fri, 2014-12-12 at 17:58 +0200, Ömer Sinan Ağacan wrote:
> >>> Hi all,
> >>>
> >>> I'm having a horrible bug in my program: a print statement that
> >>> doesn't force any values(e.g. it just prints a static string)
> >>> effecting the behavior of the program.
> >>>
> >>> I tried hard to produce a minimal example, but couldn't manage it. So
> >>> instead I'm just going to point to the source code of my program:
> >>> https://github.com/osa1/rho-torrent/blob/master/src/Rho/Listener.hs#L125
> >>>
> >>> If I remove this print statement everything goes weird. I think when I
> >>> remove this statement some effects are not happening, or happening in
> >>> wrong times.
> >>>
> >>> Here's how I'm testing the different behavior: This is a network
> >>> application and I'm creating an environment in my system and making
> >>> this program talk to another program.
> >>>
> >>> I run my program 10 times without the print statement, and run 10 times with it.
> >>>
> >>> Both groups produce same output in every time, but outputs of first
> >>> group and second group are different from each other. (apart from
> >>> extra prints, of course)
> >>>
> >>> So this print statement effects some other things, and expected
> >>> behavior is the one happening with print statement.
> >>>
> >>> I know the program is big for anyone to figure things in short amount
> >>> of time, I'm just looking for tips and pitfalls that I may be falling.
> >>> Does anyone have any ideas what I may be doing wrong? Note that the
> >>> program doesn't use any unsafe stuff.
> >>>
> >>> Thanks in advance.
> >>> _______________________________________________
> >>> Haskell-Cafe mailing list
> >>> Haskell-Cafe at haskell.org
> >>> http://www.haskell.org/mailman/listinfo/haskell-cafe
> >>
> >>




More information about the Haskell-Cafe mailing list