<div dir="ltr"><div>Hi Zhen,</div><div><br></div><div>Although you might be resolved, there are some information.</div><div><br></div><div>In your example code, threads are waiting a MVar for each IO(print). </div><div>(thread switch by self yield rather than timer-based(preemptive) scheduling) </div><div><br></div><div>Maybe, these information would be helpful.</div><div><br></div><div>    Parallel and Concurrent Programming in Haskell</div><div>    Chapter 7. Basic Concurrency: Threads and MVars</div><div>    <a href="http://chimera.labs.oreilly.com/books/1230000000929/ch07.html">http://chimera.labs.oreilly.com/books/1230000000929/ch07.html</a></div><div><br></div><div>    The GHC scheduler</div><div>    <a href="http://blog.ezyang.com/2013/01/the-ghc-scheduler/">http://blog.ezyang.com/2013/01/the-ghc-scheduler/</a></div><div><br></div><div>    Runtime Support for Multicore Haskell</div><div>    <a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/multicore-ghc.pdf">http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/multicore-ghc.pdf</a></div><div><br></div><div>    Extending the Haskell Foreign Function Interface with Concurrency</div><div>    <a href="http://community.haskell.org/~simonmar/papers/conc-ffi.pdf">http://community.haskell.org/~simonmar/papers/conc-ffi.pdf</a></div><div><br></div><div>And, ThreadScope and eventlog are here.</div><div><br></div><div>    Parallel and Concurrent Programming in Haskell</div><div>    15. Debugging, Tuning, and Interfacing with Foreign Code</div><div>    Event Logging and ThreadScope</div><div>    <a href="http://chimera.labs.oreilly.com/books/1230000000929/ch15.html#sec_conc_eventlogging">http://chimera.labs.oreilly.com/books/1230000000929/ch15.html#sec_conc_eventlogging</a></div><div><br></div><div>    ThreadScope</div><div>    <a href="https://wiki.haskell.org/ThreadScope">https://wiki.haskell.org/ThreadScope</a></div><div><br></div><div><br></div><div>So, few image.</div><div>    <a href="http://takenobu-hs.github.io/downloads/haskell_ghc_illustrated.pdf#page=82">http://takenobu-hs.github.io/downloads/haskell_ghc_illustrated.pdf#page=82</a></div><div>    <a href="http://takenobu-hs.github.io/downloads/haskell_ghc_illustrated.pdf#page=47">http://takenobu-hs.github.io/downloads/haskell_ghc_illustrated.pdf#page=47</a></div><div><br></div><div><br></div><div>Cheers,</div><div>Takenobu</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-07-05 14:10 GMT+09:00 Zhen Zhang <span dir="ltr"><<a href="mailto:izgzhen@gmail.com" target="_blank">izgzhen@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">Hi Ryan,</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">Thank for your help. But it turned out to be not working for me. I even commented out the `startTimer` and `stopTimer` in `rts/Timer.c`, but it seems not working as well.</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">For example. this program:</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">main = do</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><span style="white-space:pre-wrap"> </span>forkIO $ forever $ print “a”</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><span style="white-space:pre-wrap">  </span>forkIO $ forever $ print “b”</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><span style="white-space:pre-wrap">  </span>threadDelay 100000</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">When I added the `-threaded`, it will schedule normally, despite whether I commented out some code or add `-V0`. When I dropped  `-threaded`, the `timerManager` stopped working as well, so it doesn’t make sense to me. Bad luck, but thank you all the way.</div><span class="HOEnZb"><font color="#888888"><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">Zhen</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div> <div><div style="font-family:helvetica,arial;font-size:13px">-- <br>Zhen Zhang<br>USTC, China</div></div></font></span><div><div class="h5"> <br><p style="color:#000">On July 4, 2015 at 10:08:44 PM, Ryan Yates (<a href="mailto:fryguybob@gmail.com" target="_blank">fryguybob@gmail.com</a>) wrote:</p> <blockquote type="cite"><span><div><div></div><div>






<div dir="ltr">Hi Zhen,
<div><br></div>
<div>The RTS flag -V sets the tick interval (setting to 0
disables).  If you grep for `RtsFlags.MiscFlags.tickInterval`
you can find where it gets used.  Hope this helps.</div>
<div><br></div>
<div>Ryan</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Sat, Jul 4, 2015 at 6:25 AM, Zhen Zhang
<span dir="ltr"><<a href="mailto:izgzhen@gmail.com" target="_blank">izgzhen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">
<div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">
Hi,</div>
<div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">
<br></div>
<div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">
I am trying to stop the GHC thread scheduler from atomically do
round-robin scheduling. It might be strange that I am asking for
that, in fact, my intention is to implement the “Lightweight
Concurrency” on top of current RTS system. I am trying to use
`GHC.Event`’s timeout mechanism to interfere with the scheduling
behavior and it seems working a bit. But the automatic scheduling
at the same time by RTS renders this effort invalid.</div>
<div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">
<br></div>
<div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">
For this part, I have tried to modify `rts/Scheduler.c`, masked
some `startTimer` in `schedule()`, change the `appendToQueue` to
`pushOnQueue` in `scheduleHandleYield` but nothing really works.
(The GHC is still doing RR scheduling, even I changed some key code
I thought)</div>
<div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">
<br></div>
<div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">
So I am curious if anyone familiar with the RTS could give me some
suggestions on this problem.</div>
<div><br></div>
<div>Thanks a lot!</div>
<div>
<div style="font-family:helvetica,arial;font-size:13px">
<span><font color="#888888"><br>
Zhen</font></span></div>
<div style="font-family:helvetica,arial;font-size:13px">
<span><font color="#888888"><br></font></span></div>
<div style="font-family:helvetica,arial;font-size:13px">
<span><font color="#888888"><br></font></span></div>
</div>
</div>
<br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>

<br></blockquote>
</div>
<br></div>


</div></div></span></blockquote></div></div></div><br>_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div><br></div>