<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Possible thread deadlock/hang in al_detach_voice() ?</title>
		<link>http://www.allegro.cc/forums/view/613608</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 07 Dec 2013 07:41:46 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello, this is my first post on allegro.cc. Actually, I&#39;m not used to posting on the internet at all (usually when I run into a programming problem I just use a search engine until I find a way to fix it), so this post is probably going to be rather stilted. I apologize in advance.</p><p>While working on a heavy C++11 wrapper for Allegro 5 to use in my game engine (which is not really an engine, just a large collection of classes), I encountered a problem when using al_detach_voice(), and also al_detach_mixer(), where the ALLEGRO_MIXER is one that is attached to an ALLEGRO_VOICE.</p><p>The problem is that, every ~5 to ~20 program executions, the code will hang at a call to al_detach_voice(). GDB says the problem occurs starting from this line, in addons/audio/kcm_voice.c, at line 379. I can provide a full backtrace if needed.</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span>voice-&gt;driver-&gt;stop_voice<span class="k2">(</span>voice<span class="k2">)</span><span class="k2">;</span>
</div></div><p>

Further inspection of GDB&#39;s backtrace would seem to indicate that Allegro is using the pulseaudio driver, but I would not know if this is specific to that driver.</p><p>I have tested and found that the exact same problem can be demonstrated with al_detach_mixer() as well (according to GDB, both call into the same underlying code in addons/audio/kcm_voice.c).</p><p>The version of Allegro I am using is Allegro 5.0.10 (debug) - the latest stable, I believe. I have not tested the WIP version, mainly because I want to use the stable release, but if someone needs me to test the unstable version, I can (assuming I can convince GCC to compile it, that is).</p><p>Here is an example program which should demonstrate the problem. You may need to run the program several times; I am able to reproduce the problem more or less reliably that way. Sometimes the program will deadlock/hang at the <i>very first</i> call to al_detach_voice().</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">   1</span>
<span class="number">   2</span><span class="c">// This program is intended to demonstrate a possible problem in</span>
<span class="number">   3</span><span class="c">// al_detach_voice().</span>
<span class="number">   4</span>
<span class="number">   5</span><span class="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">   6</span><span class="p">#include &lt;allegro5/allegro_audio.h&gt;</span>
<span class="number">   7</span>
<span class="number">   8</span><span class="p">#include &lt;iostream&gt;</span>
<span class="number">   9</span><span class="p">#include &lt;cassert&gt;</span>
<span class="number">  10</span>
<span class="number">  11</span>
<span class="number">  12</span>
<span class="number">  13</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> <span class="c">/* argc */</span>, <span class="k1">char</span><span class="k3">*</span><span class="k3">*</span> <span class="c">/* argv */</span><span class="k2">)</span>
<span class="number">  14</span><span class="k2">{</span>
<span class="number">  15</span>  std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Starting tests ..."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number">  16</span>
<span class="number">  17</span>  <span class="c">// Initialize Allegro Base.</span>
<span class="number">  18</span>  <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  19</span>  <span class="k2">{</span>
<span class="number">  20</span>    std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"al_init() failed."</span><span class="k2">;</span>
<span class="number">  21</span>    <span class="k1">return</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number">  22</span>  <span class="k2">}</span>
<span class="number">  23</span>
<span class="number">  24</span>  <span class="c">// Initialize Allegro Audio add-on.</span>
<span class="number">  25</span>  <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_install_audio"><span class="a">al_install_audio</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  26</span>  <span class="k2">{</span>
<span class="number">  27</span>    std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"al_install_audio() failed."</span><span class="k2">;</span>
<span class="number">  28</span>    <span class="k1">return</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number">  29</span>  <span class="k2">}</span>
<span class="number">  30</span>
<span class="number">  31</span>  <span class="c">// Sanity checks.</span>
<span class="number">  32</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_is_system_installed"><span class="a">al_is_system_installed</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  33</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_is_audio_installed"><span class="a">al_is_audio_installed</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  34</span>
<span class="number">  35</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_VOICE"><span class="a">ALLEGRO_VOICE</span></a><span class="k3">*</span> pVoice <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number">  36</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_MIXER"><span class="a">ALLEGRO_MIXER</span></a><span class="k3">*</span> pMixer <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number">  37</span>
<span class="number">  38</span>  <span class="c">// Configuration variables.</span>
<span class="number">  39</span>  <span class="k1">const</span> <span class="k1">unsigned</span> <span class="k1">int</span> frequency <span class="k3">=</span> <span class="n">44100</span><span class="k2">;</span>
<span class="number">  40</span>  <span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_CHANNEL_CONF"><span class="a">ALLEGRO_CHANNEL_CONF</span></a> channel_conf <span class="k3">=</span> ALLEGRO_CHANNEL_CONF_2<span class="k2">;</span>
<span class="number">  41</span>  <span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_AUDIO_DEPTH"><span class="a">ALLEGRO_AUDIO_DEPTH</span></a> audio_depth <span class="k3">=</span> ALLEGRO_AUDIO_DEPTH_FLOAT32<span class="k2">;</span>
<span class="number">  42</span>
<span class="number">  43</span>  <span class="c">// Create the voice and mixer.</span>
<span class="number">  44</span>  pVoice <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_voice"><span class="a">al_create_voice</span></a><span class="k2">(</span>frequency, audio_depth, channel_conf<span class="k2">)</span><span class="k2">;</span>
<span class="number">  45</span>
<span class="number">  46</span>  <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>pVoice<span class="k2">)</span>
<span class="number">  47</span>  <span class="k2">{</span>
<span class="number">  48</span>    std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"al_create_voice() failed."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number">  49</span>    <span class="k1">return</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number">  50</span>  <span class="k2">}</span>
<span class="number">  51</span>
<span class="number">  52</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>pVoice<span class="k2">)</span><span class="k2">;</span>
<span class="number">  53</span>
<span class="number">  54</span>  pMixer <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_mixer"><span class="a">al_create_mixer</span></a><span class="k2">(</span>frequency, audio_depth, channel_conf<span class="k2">)</span><span class="k2">;</span>
<span class="number">  55</span>
<span class="number">  56</span>  <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>pMixer<span class="k2">)</span>
<span class="number">  57</span>  <span class="k2">{</span>
<span class="number">  58</span>    std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"al_create_mixer() failed."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number">  59</span>    <span class="k1">return</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number">  60</span>  <span class="k2">}</span>
<span class="number">  61</span>
<span class="number">  62</span>  <span class="c">// Sanity checks.</span>
<span class="number">  63</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>pMixer<span class="k2">)</span><span class="k2">;</span>
<span class="number">  64</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>pVoice<span class="k2">)</span><span class="k2">;</span>
<span class="number">  65</span>
<span class="number">  66</span>  <span class="c">// Perform one initial attach/detach before the main test loop. Sometimes the</span>
<span class="number">  67</span>  <span class="c">// program will hang on the very first call to al_detach_voice() or</span>
<span class="number">  68</span>  <span class="c">// al_detach_mixer().</span>
<span class="number">  69</span>  <span class="k2">{</span>
<span class="number">  70</span>    std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Test #0 ... "</span><span class="k2">;</span>
<span class="number">  71</span>    std::cout.flush<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  72</span>    <span class="k1">bool</span> result <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_attach_mixer_to_voice"><span class="a">al_attach_mixer_to_voice</span></a><span class="k2">(</span>pMixer, pVoice<span class="k2">)</span><span class="k2">;</span>
<span class="number">  73</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>result<span class="k2">)</span><span class="k2">;</span>
<span class="number">  74</span>    <a href="http://www.allegro.cc/manual/al_detach_voice"><span class="a">al_detach_voice</span></a><span class="k2">(</span>pVoice<span class="k2">)</span><span class="k2">;</span>
<span class="number">  75</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_get_mixer_attached"><span class="a">al_get_mixer_attached</span></a><span class="k2">(</span>pMixer<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  76</span>    std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"\tsucceeded."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number">  77</span>  <span class="k2">}</span>
<span class="number">  78</span>
<span class="number">  79</span>
<span class="number">  80</span>
<span class="number">  81</span>  <span class="c">// Begin testing al_attach_mixer_to_voice() and al_detach_voice() multiple</span>
<span class="number">  82</span>  <span class="c">// times ...</span>
<span class="number">  83</span>  <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span> i <span class="k3">&lt;</span><span class="k3">=</span> <span class="n">1000</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>i<span class="k2">)</span>
<span class="number">  84</span>  <span class="k2">{</span>
<span class="number">  85</span>    std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Test #"</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> i <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">" ... "</span><span class="k2">;</span>
<span class="number">  86</span>    std::cout.flush<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  87</span>
<span class="number">  88</span>    <span class="k1">bool</span> result <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_attach_mixer_to_voice"><span class="a">al_attach_mixer_to_voice</span></a><span class="k2">(</span>pMixer, pVoice<span class="k2">)</span><span class="k2">;</span>
<span class="number">  89</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>result<span class="k2">)</span><span class="k2">;</span>
<span class="number">  90</span>
<span class="number">  91</span>    <span class="c">// Here is one of the troublesome functions. It hangs within its call stack.</span>
<span class="number">  92</span>    <a href="http://www.allegro.cc/manual/al_detach_voice"><span class="a">al_detach_voice</span></a><span class="k2">(</span>pVoice<span class="k2">)</span><span class="k2">;</span>
<span class="number">  93</span>
<span class="number">  94</span>    <span class="c">// Calling this function instead of al_detach_voice() also demonstrates the</span>
<span class="number">  95</span>    <span class="c">// same problem.</span>
<span class="number">  96</span>    <span class="c">// al_detach_mixer(pMixer);</span>
<span class="number">  97</span>
<span class="number">  98</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_get_mixer_attached"><span class="a">al_get_mixer_attached</span></a><span class="k2">(</span>pMixer<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  99</span>    std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"\tsucceeded."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number"> 100</span>  <span class="k2">}</span>
<span class="number"> 101</span>
<span class="number"> 102</span>
<span class="number"> 103</span>
<span class="number"> 104</span>  <span class="c">// Clean up.</span>
<span class="number"> 105</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>pMixer<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 106</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>pVoice<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 107</span>  <a href="http://www.allegro.cc/manual/al_destroy_mixer"><span class="a">al_destroy_mixer</span></a><span class="k2">(</span>pMixer<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 108</span>  pMixer <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 109</span>  <a href="http://www.allegro.cc/manual/al_destroy_voice"><span class="a">al_destroy_voice</span></a><span class="k2">(</span>pVoice<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 110</span>  pVoice <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 111</span>
<span class="number"> 112</span>  <span class="c">// Shutdown Allegro Audio add-on; Allegro Base.</span>
<span class="number"> 113</span>  <a href="http://www.allegro.cc/manual/al_uninstall_audio"><span class="a">al_uninstall_audio</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 114</span>  <a href="http://www.allegro.cc/manual/al_uninstall_system"><span class="a">al_uninstall_system</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 115</span>
<span class="number"> 116</span>  <span class="c">// Sanity checks.</span>
<span class="number"> 117</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_is_system_installed"><span class="a">al_is_system_installed</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 118</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_is_audio_installed"><span class="a">al_is_audio_installed</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 119</span>  std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Tests finished."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number"> 120</span>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 121</span><span class="k2">}</span>
</div></div><p>

Yes, I <i>know</i> attaching and detaching 1000 times is generally not realistic. But any little imperfection in Allegro bugs me. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>I hope I am not accidentally disturbing the wrong part of the forum ....</p><p>If I missed something that someone will need, please let me know.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bluebird)</author>
		<pubDate>Fri, 06 Dec 2013 10:07:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tried putting a delay as long as 0.05 seconds before and after the al_detach_voice and it still hung on the 12&#39;th attempt (using a script and modified program output to write attempt number on same line).  I&#39;m currently trying it at 0.5 delay, but obviously it&#39;s going to take several hours to get as far as 12 runs.  If it hangs then, it&#39;s obviously not to be taken lightly.  The modified cpp file and script are in the paperclip if you want to try them.  I didn&#39;t know how to put in a carrage return with cout so I used printf. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /></p><p>[EDIT]</p><p>Oops!  I forgot I started playing with it in Slackware which doesn&#39;t have pulse audio, and grabbed t.cpp from the wrong &#39;home&#39;.  Use the t2.cpp file.</p><p>BTW, Matt, my list of attachments in control center only shows the first couple dozen attachments and I can&#39;t delete t.cpp.</p><p>Also (Matt) Firefox doesn&#39;t copy line breaks when grabbing code from the box, it winds up just being one long line.  I&#39;ve been working around that by opening the post in Konqueror.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Fri, 06 Dec 2013 13:17:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You don&#39;t need to apologise for reporting a bug.</p><p>I haven&#39;t yet reproduced it on my Slackware machine (with ALSA) or Ubuntu VM (with Pulseaudio) so stack traces of the different threads would be very helpful.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Fri, 06 Dec 2013 13:43:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I managed to get this (with the original code and debugging libraries), don&#39;t know if it helps much.  It hung before printing &quot;succeeded&quot; on test 232, so I control-C&#39;ed it.</p><pre>
Test #228 ...   succeeded.
Test #229 ...   succeeded.
Test #230 ...   succeeded.
Test #231 ...   succeeded.
Test #232 ... ^C  
Program received signal SIGINT, Interrupt.
pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:162
162     ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: No such file or directory.
(gdb) nb
Undefined command: &quot;nb&quot;.  Try &quot;help&quot;.
(gdb) b
Breakpoint 1 at 0x7ffff62cad84: file ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S, line 162.
(gdb) backtrace 
#0  pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:162
#1  0x00007ffff71d38ed in _al_cond_wait (cond=0x62e510, mutex=0x62e3d0)
    at /home/prog/allegro-5.1.7/include/allegro5/platform/aintuthr.h:81
#2  0x00007ffff71dd2dc in al_wait_cond (cond=0x62e510, mutex=0x62e3d0) at /home/prog/allegro-5.1.7/src/threads.c:365
#3  0x00007ffff7bcbfc1 in pulseaudio_stop_voice (voice=0x628af0)
    at /home/prog/allegro-5.1.7/addons/audio/pulseaudio.c:359
#4  0x00007ffff7bc95a2 in al_detach_voice (voice=0x628af0) at /home/prog/allegro-5.1.7/addons/audio/kcm_voice.c:379
#5  0x000000000040115d in main () at t3.cpp:92
(gdb) 
</pre><p>

Or did you mean a core dump?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Fri, 06 Dec 2013 14:07:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Turns out I was testing the ALSA driver on Ubuntu <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />  I can reproduce it easily as well. This particular deadlock is specific to the Allegro 5.0.10 Pulseaudio driver (and also on 5.1). It&#39;s an easy mistake to make (yes, it was me) so other backends may have a similar mistake.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Fri, 06 Dec 2013 17:03:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/revision/993678">Arthur Kalliokoski</a> said:</div><div class="quote"><p>Or did you mean a core dump?</p></div></div><p>

It hasn&#39;t core dumped for me at all. It just stops and does nothing until I ctrl+c it.</p><p>@Peter Wang<br />Okay, here is the backtrace:</p><pre class="terminal scroll">
(gdb) start
Temporary breakpoint 8 at 0x400f0c: file /home/yosef/source/code-blocks-projects/al_detach_voice_t2/main.cpp, line 19.
Starting program: /home/yosef/source/code-blocks-projects/al_detach_voice_t2/./al_detach_voice 
[Thread debugging using libthread_db enabled]
Using host libthread_db library &quot;/lib/x86_64-linux-gnu/libthread_db.so.1&quot;.

Temporary breakpoint 8, main (argc=1, argv=0x7fffffffde08) at /home/yosef/source/code-blocks-projects/al_detach_voice_t2/main.cpp:19
19        double delaytime = 0.01;
(gdb) continue
Continuing.
[New Thread 0x7ffff1ca8700 (LWP 31854)]
[New Thread 0x7fffed4a6700 (LWP 31855)]
[New Thread 0x7fffecca5700 (LWP 31856)]
^C
Program received signal SIGINT, Interrupt.
pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
185     ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: No such file or directory.
(gdb) backtrace
#0  pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1  0x00007ffff7ac7cd5 in _al_cond_wait (cond=0x62ee00, mutex=0x62f0c0) at /home/yosef/source/allegro-5.0.10/include/allegro5/platform/aintuthr.h:81
#2  0x00007ffff7ad0209 in al_wait_cond (cond=0x62ee00, mutex=0x62f0c0) at /home/yosef/source/allegro-5.0.10/src/threads.c:365
#3  0x00007ffff78582d7 in pulseaudio_stop_voice (voice=0x610e10) at /home/yosef/source/allegro-5.0.10/addons/audio/pulseaudio.c:359
#4  0x00007ffff7856092 in al_detach_voice (voice=0x610e10) at /home/yosef/source/allegro-5.0.10/addons/audio/kcm_voice.c:379
#5  0x000000000040112d in main (argc=1, argv=0x7fffffffde08) at /home/yosef/source/code-blocks-projects/al_detach_voice_t2/main.cpp:79
(gdb) thread apply all bt

Thread 4 (Thread 0x7fffecca5700 (LWP 31856)):
#0  __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135
#1  0x00007ffff6c6015c in _L_lock_982 () from /lib/x86_64-linux-gnu/libpthread.so.0
#2  0x00007ffff6c5ffab in __GI___pthread_mutex_lock (mutex=0x61ff18) at pthread_mutex_lock.c:64
#3  0x00007ffff7ac7c4a in _al_mutex_lock (m=0x61ff10) at /home/yosef/source/allegro-5.0.10/include/allegro5/platform/aintuthr.h:60
#4  0x00007ffff7acffdc in al_lock_mutex (mutex=0x61ff10) at /home/yosef/source/allegro-5.0.10/src/threads.c:310
#5  0x00007ffff785503f in _al_voice_update (voice=0x610e10, samples=0x7fffecca4cd4) at /home/yosef/source/allegro-5.0.10/addons/audio/kcm_voice.c:45
#6  0x00007ffff7857bfd in pulseaudio_update (self=0x6118c0, data=0x610e10) at /home/yosef/source/allegro-5.0.10/addons/audio/pulseaudio.c:174
#7  0x00007ffff7acf37f in thread_func_trampoline (inner=0x6118c0, _outer=0x6118c0) at /home/yosef/source/allegro-5.0.10/src/threads.c:80
#8  0x00007ffff7b3951d in thread_proc_trampoline (data=0x6118c0) at /home/yosef/source/allegro-5.0.10/src/unix/uxthread.c:36
#9  0x00007ffff6c5df6e in start_thread (arg=0x7fffecca5700) at pthread_create.c:311
#10 0x00007ffff72719cd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

Thread 3 (Thread 0x7fffed4a6700 (LWP 31855)):
#0  0x00007ffff7264f7d in poll () at ../sysdeps/unix/syscall-template.S:81
#1  0x00007ffff5c8f041 in ?? () from /usr/lib/x86_64-linux-gnu/libpulse.so.0
#2  0x00007ffff5c8084c in pa_mainloop_poll () from /usr/lib/x86_64-linux-gnu/libpulse.so.0
#3  0x00007ffff5c80ede in pa_mainloop_iterate () from /usr/lib/x86_64-linux-gnu/libpulse.so.0
#4  0x00007ffff5c80f90 in pa_mainloop_run () from /usr/lib/x86_64-linux-gnu/libpulse.so.0
#5  0x00007ffff5c8eff3 in ?? () from /usr/lib/x86_64-linux-gnu/libpulse.so.0
#6  0x00007ffff3d31ee8 in ?? () from /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so
#7  0x00007ffff6c5df6e in start_thread (arg=0x7fffed4a6700) at pthread_create.c:311
#8  0x00007ffff72719cd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

Thread 2 (Thread 0x7ffff1ca8700 (LWP 31854)):
#0  0x00007ffff7269de3 in select () at ../sysdeps/unix/syscall-template.S:81
#1  0x00007ffff7b3dbd5 in _al_xwin_background_thread (self=0x6104b0, arg=0x610450) at /home/yosef/source/allegro-5.0.10/src/x/xevents.c:184
#2  0x00007ffff7b3951d in thread_proc_trampoline (data=0x6104b0) at /home/yosef/source/allegro-5.0.10/src/unix/uxthread.c:36
#3  0x00007ffff6c5df6e in start_thread (arg=0x7ffff1ca8700) at pthread_create.c:311
#4  0x00007ffff72719cd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

Thread 1 (Thread 0x7ffff7fbd880 (LWP 31853)):
#0  pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1  0x00007ffff7ac7cd5 in _al_cond_wait (cond=0x62ee00, mutex=0x62f0c0) at /home/yosef/source/allegro-5.0.10/include/allegro5/platform/aintuthr.h:81
#2  0x00007ffff7ad0209 in al_wait_cond (cond=0x62ee00, mutex=0x62f0c0) at /home/yosef/source/allegro-5.0.10/src/threads.c:365
#3  0x00007ffff78582d7 in pulseaudio_stop_voice (voice=0x610e10) at /home/yosef/source/allegro-5.0.10/addons/audio/pulseaudio.c:359
#4  0x00007ffff7856092 in al_detach_voice (voice=0x610e10) at /home/yosef/source/allegro-5.0.10/addons/audio/kcm_voice.c:379
#5  0x000000000040112d in main (argc=1, argv=0x7fffffffde08) at /home/yosef/source/code-blocks-projects/al_detach_voice_t2/main.cpp:79
(gdb) 
</pre><p>

[Edit] I should note that this backtrace is with Arthur Kalliokoski&#39;s code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bluebird)</author>
		<pubDate>Fri, 06 Dec 2013 21:11:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>valgrind includes a nice thread debug tool iirc. I think its called helgrind.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 06 Dec 2013 23:00:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve never used Valgrind&#39;s helgrind tool before so I have no idea whether this is going to be helpful .... The test program hung during the execution, so I pressed ctrl+c because I didn&#39;t know what else to do, and then helgrind wrote some more stuff. Here it is:</p><pre class="terminal scroll">yosef@ArkLegacy-7750G:~/source/code-blocks-projects/al_detach_voice_t2$ valgrind --tool=helgrind ./al_detach_voice
==375== Helgrind, a thread error detector
==375== Copyright (C) 2007-2012, and GNU GPL&#39;d, by OpenWorks LLP et al.
==375== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==375== Command: ./al_detach_voice
==375== 
==375== ---Thread-Announcement------------------------------------------
==375== 
==375== Thread #1 is the program&#39;s root thread
==375== 
==375== ----------------------------------------------------------------
==375== 
==375== Thread #1: pthread_cond_destroy: destruction of unknown cond var
==375==    at 0x4C2D7F8: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x742AE09: ??? (in /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0)
==375==    by 0x742AED1: xcb_wait_for_reply (in /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0)
==375==    by 0x5FF64E6: _XReply (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==375==    by 0x5FEC983: XQueryExtension (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==375==    by 0x5FE0C31: XInitExtension (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==375==    by 0x6049123: XkbUseExtension (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==375==    by 0x5FE7302: XOpenDisplay (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==375==    by 0x4F1BC63: xglx_initialize (xsystem.c:38)
==375==    by 0x4EA363E: find_system (system.c:61)
==375==    by 0x4EA3A07: al_install_system (system.c:241)
==375==    by 0x400FA3: main (main.cpp:23)
==375== 
==375== ---Thread-Announcement------------------------------------------
==375== 
==375== Thread #3 was created
==375==    at 0x57CB98E: clone (clone.S:76)
==375==    by 0x5DA3F24: do_clone.constprop.4 (createthread.c:74)
==375==    by 0x5DA564D: pthread_create@@GLIBC_2.2.5 (createthread.c:244)
==375==    by 0x4C2E870: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x8D0272C: pa_thread_new (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x6D9816B: pa_threaded_mainloop_start (in /usr/lib/x86_64-linux-gnu/libpulse.so.0.16.2)
==375==    by 0x6B65B86: pa_simple_new (in /usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.0.4)
==375==    by 0x51C3F58: pulseaudio_allocate_voice (pulseaudio.c:248)
==375==    by 0x51C1255: al_create_voice (kcm_voice.c:84)
==375==    by 0x401065: main (main.cpp:49)
==375== 
==375== ----------------------------------------------------------------
==375== 
==375== Lock at 0xAF94CA0 was first observed
==375==    at 0x4C2F8EA: pthread_mutex_init (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x8D01D89: pa_mutex_new (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x6D980DE: pa_threaded_mainloop_new (in /usr/lib/x86_64-linux-gnu/libpulse.so.0.16.2)
==375==    by 0x6B65AEC: pa_simple_new (in /usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.0.4)
==375==    by 0x51C3F58: pulseaudio_allocate_voice (pulseaudio.c:248)
==375==    by 0x51C1255: al_create_voice (kcm_voice.c:84)
==375==    by 0x401065: main (main.cpp:49)
==375== 
==375== Lock at 0xAF94E90 was first observed
==375==    at 0x4C2F8EA: pthread_mutex_init (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x8D01D89: pa_mutex_new (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8D025A5: pa_static_mutex_get (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8CEDFDE: pa_once_begin (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8CEE14A: pa_run_once (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8D02ECC: ??? (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x4C2EA06: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x5DA4F6D: start_thread (pthread_create.c:311)
==375==    by 0x57CB9CC: clone (clone.S:113)
==375== 
==375== Possible data race during read of size 4 at 0x8F23C28 by thread #1
==375== Locks held: 1, at address 0xAF94CA0
==375==    at 0x8CEDFC1: pa_once_begin (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8CEE14A: pa_run_once (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8D02E23: pa_thread_self (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x6D986FC: pa_threaded_mainloop_wait (in /usr/lib/x86_64-linux-gnu/libpulse.so.0.16.2)
==375==    by 0x6B65BBD: pa_simple_new (in /usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.0.4)
==375==    by 0x51C3F58: pulseaudio_allocate_voice (pulseaudio.c:248)
==375==    by 0x51C1255: al_create_voice (kcm_voice.c:84)
==375==    by 0x401065: main (main.cpp:49)
==375== 
==375== This conflicts with a previous write of size 4 by thread #3
==375== Locks held: 1, at address 0xAF94E90
==375==    at 0x8CEE073: pa_once_end (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8D02ECC: ??? (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x4C2EA06: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x5DA4F6D: start_thread (pthread_create.c:311)
==375==    by 0x57CB9CC: clone (clone.S:113)
==375== 
==375== ----------------------------------------------------------------
==375== 
==375== Lock at 0xAF94CA0 was first observed
==375==    at 0x4C2F8EA: pthread_mutex_init (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x8D01D89: pa_mutex_new (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x6D980DE: pa_threaded_mainloop_new (in /usr/lib/x86_64-linux-gnu/libpulse.so.0.16.2)
==375==    by 0x6B65AEC: pa_simple_new (in /usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.0.4)
==375==    by 0x51C3F58: pulseaudio_allocate_voice (pulseaudio.c:248)
==375==    by 0x51C1255: al_create_voice (kcm_voice.c:84)
==375==    by 0x401065: main (main.cpp:49)
==375== 
==375== Lock at 0xAF94E90 was first observed
==375==    at 0x4C2F8EA: pthread_mutex_init (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x8D01D89: pa_mutex_new (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8D025A5: pa_static_mutex_get (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8CEDFDE: pa_once_begin (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8CEE14A: pa_run_once (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8D02ECC: ??? (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x4C2EA06: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x5DA4F6D: start_thread (pthread_create.c:311)
==375==    by 0x57CB9CC: clone (clone.S:113)
==375== 
==375== Possible data race during read of size 8 at 0x8F23C30 by thread #1
==375== Locks held: 1, at address 0xAF94CA0
==375==    at 0x8D02E24: pa_thread_self (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x6D986FC: pa_threaded_mainloop_wait (in /usr/lib/x86_64-linux-gnu/libpulse.so.0.16.2)
==375==    by 0x6B65BBD: pa_simple_new (in /usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.0.4)
==375==    by 0x51C3F58: pulseaudio_allocate_voice (pulseaudio.c:248)
==375==    by 0x51C1255: al_create_voice (kcm_voice.c:84)
==375==    by 0x401065: main (main.cpp:49)
==375== 
==375== This conflicts with a previous write of size 8 by thread #3
==375== Locks held: 1, at address 0xAF94E90
==375==    at 0x8D02C70: ??? (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8CEE161: pa_run_once (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8D02ECC: ??? (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x4C2EA06: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x5DA4F6D: start_thread (pthread_create.c:311)
==375==    by 0x57CB9CC: clone (clone.S:113)
==375== 
==375== ----------------------------------------------------------------
==375== 
==375== Lock at 0xAF94CA0 was first observed
==375==    at 0x4C2F8EA: pthread_mutex_init (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x8D01D89: pa_mutex_new (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x6D980DE: pa_threaded_mainloop_new (in /usr/lib/x86_64-linux-gnu/libpulse.so.0.16.2)
==375==    by 0x6B65AEC: pa_simple_new (in /usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.0.4)
==375==    by 0x51C3F58: pulseaudio_allocate_voice (pulseaudio.c:248)
==375==    by 0x51C1255: al_create_voice (kcm_voice.c:84)
==375==    by 0x401065: main (main.cpp:49)
==375== 
==375== Possible data race during read of size 4 at 0xAF84CE0 by thread #1
==375== Locks held: 1, at address 0xAF94CA0
==375==    at 0x8D02D35: pa_tls_get (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8D02E2F: pa_thread_self (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x6D986FC: pa_threaded_mainloop_wait (in /usr/lib/x86_64-linux-gnu/libpulse.so.0.16.2)
==375==    by 0x6B65BBD: pa_simple_new (in /usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.0.4)
==375==    by 0x51C3F58: pulseaudio_allocate_voice (pulseaudio.c:248)
==375==    by 0x51C1255: al_create_voice (kcm_voice.c:84)
==375==    by 0x401065: main (main.cpp:49)
==375== 
==375== Address 0xAF84CE0 is 0 bytes inside a block of size 4 alloc&#39;d
==375==    at 0x4C2A35B: malloc (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x8CCDA46: pa_xmalloc (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8D02C32: pa_tls_new (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8D02C6F: ??? (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8CEE161: pa_run_once (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x8D02ECC: ??? (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so)
==375==    by 0x4C2EA06: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x5DA4F6D: start_thread (pthread_create.c:311)
==375==    by 0x57CB9CC: clone (clone.S:113)
==375== 
^C==375== ----------------------------------------------------------------
==375== 
==375== Thread #1: Exiting thread still holds 1 lock
==375==    at 0x5DA8C84: pthread_cond_wait@@GLIBC_2.3.2 (pthread_cond_wait.S:185)
==375==    by 0x4C2EBA3: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==375==    by 0x4E9CCD4: _al_cond_wait (aintuthr.h:81)
==375==    by 0x4EA5208: al_wait_cond (threads.c:365)
==375==    by 0x51C42D6: pulseaudio_stop_voice (pulseaudio.c:359)
==375==    by 0x51C2091: al_detach_voice (kcm_voice.c:379)
==375==    by 0x401227: main (main.cpp:99)
==375== 
==375== 
==375== For counts of detected and suppressed errors, rerun with: -v
==375== Use --history-level=approx or =none to gain increased speed, at
==375== the cost of reduced accuracy of conflicting-access information
==375== ERROR SUMMARY: 9 errors from 5 contexts (suppressed: 599944 from 3460)
Killed
</pre><p>

I have no experience with Allegro&#39;s source (unfortunately) so I would have difficulty being more helpful than this. :-/
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bluebird)</author>
		<pubDate>Fri, 06 Dec 2013 23:36:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Fixed in 5.1. Thanks for reporting.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Sat, 07 Dec 2013 07:41:46 +0000</pubDate>
	</item>
</rss>
