<div dir="ltr"><div>Hi all ,<br></div>it is a known bug  documented in the code too that   deadlock can occur when  teardown and helper thread is on the same  
cpu <div><div><div>[1] Referring to bfq_teardown() in bfq.c <br></div>I found a possible cause and have an amateur solution for it . <br>it 
happens because  when teardown sends a kill message [2] to helper thread , helper_msg_kill is  called to 
add the kill message in queue with other messages serialized by lwkt and
 return to teardown function .The helper thread will only receive kill 
once it has executed all other messages before it .<br>

After making this  call teardown destroy the message cache and the
 helper thread  never receives the kill message which continues 
executing and hence a deadlock.<br><br>Solution : <br>Either
 we can directly kill the helper thread ( using a global variable which 
is usually a bad idea) without adding the message to lwkt <br>

<div>ex  <br></div><div>if(kill==1)// where kill is global variable initialized zero and is set to 1 by teardown<br></div><div>break;<br><br></div>or  <br>a spinlock which makes teardown wait for the helper thread to complete reading its messages and release it .<br>

</div><div><br></div><div>Comments please.. <br></div><div>Cheers<br></div><div>Tripun<br></div><div><br>

<div>Reference<br></div>[1] <a href="http://nxr.netbsd.org/xref/src-dragonflybsd/sys/kern/dsched/bfq/bfq.c" target="_blank">http://nxr.netbsd.org/xref/src-dragonflybsd/sys/kern/dsched/bfq/bfq.c</a><br>
[2] <a href="http://nxr.netbsd.org/xref/src-dragonflybsd/sys/kern/dsched/bfq/bfq_helper_thread.c" target="_blank">http://nxr.netbsd.org/xref/src-dragonflybsd/sys/kern/dsched/bfq/bfq_helper_thread.c</a></div></div></div>