<div class="gmail_quote">On Wed, Jun 8, 2011 at 5:54 AM, David Simcha <span dir="ltr"><<a href="mailto:dsimcha@gmail.com">dsimcha@gmail.com</a>></span> wrote:<br><blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="gmail_quote">
<div class="im">On 6/7/2011 11:04 PM, SK wrote:<br>
<blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="gmail_quote">
I have a test (~100 loc) that fails immediately on 64-bit Linux without resorting to fiber migration. Using the FiberFixes branch allows it to pass. If you're interested I'd be happy to provide.<br>
Also, will I asked before but never got an answer: Is there any plan to merge FiberFixes with the the trunk?<br>
</blockquote></div><p>
Yes, please provide. I know there is still an outstanding issue with std.parallelism, but I can't reproduce it so there's not much I can do about it. I'll take any help I can get<br>
</p><p> </p></blockquote><div> </div><div>This test launches 10 threads that each launch 100 fibers that each yield 1000 times. I compile with /usr/bin/dmd -w -wi -gc. </div><div>HTH,</div><div>-steve</div><div> </div>
<div><font face="courier new,monospace">//import std.stdio;<br>import core.thread;<br>import std.stdio;<br>import std.exception;</font></div><div><font face="courier new,monospace">shared uint join_done = 0;<br>version( Windows ) { import core.sys.windows.windows; }</font></div>
<div><font face="courier new,monospace">class fiber_worker_t<br>{<br> this( uint yield_count )<br> {<br> m_done = false;<br> m_yield_count = yield_count;<br> m_fiber = new Fiber( &func );<br> }</font></div>
<div><font face="courier new,monospace"> bool call()<br> {<br> m_fiber.call();<br> return is_term();<br> }</font></div><div><font face="courier new,monospace"> bool is_term() { return( m_fiber.state() == m_fiber.State.TERM ); }<br>
bool is_done() { return( m_done ); }</font></div><div><font face="courier new,monospace">protected:<br> uint m_yield_count;<br> Fiber m_fiber;<br> bool m_done;</font></div><div><font face="courier new,monospace"> void func()<br>
{<br> uint i = m_yield_count;<br> while( --i )<br> m_fiber.yield();<br> m_done = true;<br> }<br>}</font></div><div><font face="courier new,monospace">class thread_worker_t<br>{<br> this( uint fiber_worker_count, uint fiber_yield_count )<br>
{<br> m_fiber_worker_count = fiber_worker_count;<br> m_fiber_yield_count = fiber_yield_count;<br> m_thread = new Thread( &func );<br>/*<br> // I moved this to the thread itself<br> m_fib_array = new fiber_worker_t[fiber_worker_count];<br>
foreach( ref f; m_fib_array )<br> f = new fiber_worker_t(fiber_yield_count);<br>*/<br> }</font></div><div><font face="courier new,monospace"> void start()<br> {<br> m_thread.start();<br>
}</font></div><div><font face="courier new,monospace">protected:<br> uint m_fiber_worker_count;<br> uint m_fiber_yield_count;<br> Thread m_thread;</font></div><div><font face="courier new,monospace"> // func() executes in each thread's context<br>
void func()<br> {<br> fiber_worker_t[] m_fib_array = new fiber_worker_t[m_fiber_worker_count];<br> foreach( ref f; m_fib_array )<br> f = new fiber_worker_t(m_fiber_yield_count);</font></div>
<div><font face="courier new,monospace"> // fibers are cooperative and need a driver loop<br> bool done;<br> do<br> {<br> done = true;<br> foreach( f; m_fib_array )<br> {<br>
done &= f.call();<br> // writeln( &this, " ", f, " ", &f );<br> }<br> } while( !done );</font></div><div><font face="courier new,monospace"> // verify that fibers are really done<br>
foreach( f; m_fib_array )<br> enforce( f.is_done() );</font></div><div><font face="courier new,monospace"> }<br>}</font></div><div><font face="courier new,monospace">void thread_fiber_test( const uint thread_count, const uint fiber_count, const uint fiber_yield_count )<br>
{<br> thread_worker_t[] thread_worker_array = new thread_worker_t[thread_count];<br> foreach( ref t; thread_worker_array )<br> t = new thread_worker_t(fiber_count, fiber_yield_count);</font></div><div><font face="courier new,monospace"> foreach( t; thread_worker_array ) t.start();<br>
thread_joinAll();<br> join_done = 1;<br>}</font></div><div><font face="courier new,monospace">int main()<br>{<br> const uint thread_count = 10;<br> const uint fiber_count = 100;<br> const uint fiber_yield_count = 1000;<br>
thread_fiber_test( thread_count, fiber_count, fiber_yield_count );<br> return 0;<br>}<br></font> </div></div>