<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Differences between al_run_detached_thread() and al_start_thread()</title>
		<link>http://www.allegro.cc/forums/view/609259</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 11 Jan 2012 18:54:02 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi guys...</p><p>I have a question about some threading functions, yes again... <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /></p><ol><li><p>What is the difference from <span class="source-code"><a href="http://www.allegro.cc/manual/al_run_detached_thread"><span class="a">al_run_detached_thread</span></a><span class="k2">(</span><span class="k2">)</span></span> and <span class="source-code"><a href="http://www.allegro.cc/manual/al_start_thread"><span class="a">al_start_thread</span></a><span class="k2">(</span><span class="k2">)</span></span>? The unique and obvious difference that comes to mind is the fact that with the first function you have no control over such thread, instead with the second one you have the ability to make it stop when you want. However both of them allows you you use mutexs and conds, isn&#39;t it?. </p><br /></li><li><p>When I call <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_thread"><span class="a">al_create_thread</span></a><span class="k2">(</span><span class="k2">)</span></span> the windows task manager shows that my game creates a new thread, and when I call <span class="source-code"><a href="http://www.allegro.cc/manual/al_start_thread"><span class="a">al_start_thread</span></a><span class="k2">(</span><span class="k2">)</span></span> it creates another one, but then it disappears. But when I call <span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_thread"><span class="a">al_destroy_thread</span></a><span class="k2">(</span><span class="k2">)</span></span> it only destroys one, but if I call again <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_thread"><span class="a">al_create_thread</span></a><span class="k2">(</span><span class="k2">)</span></span> and <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_thread"><span class="a">al_create_thread</span></a><span class="k2">(</span><span class="k2">)</span></span> again, it only creates one thread, and when I destroy it, again it only destroys one, so it doesn&#39;t look too bad, ex:</p></li></ol><p>threads  :  15</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_create_thread"><span class="a">al_create_thread</span></a><span class="k2">(</span><span class="k2">)</span></span><br />threads  :  16<br />`<br /><span class="source-code"><a href="http://www.allegro.cc/manual/al_start_thread"><span class="a">al_start_thread</span></a><span class="k2">(</span><span class="k2">)</span></span><br />Threads  :  17<br />Threads  :  16</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_thread"><span class="a">al_destroy_thread</span></a><span class="k2">(</span><span class="k2">)</span></span><br />Threads  :  16</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_create_thread"><span class="a">al_create_thread</span></a><span class="k2">(</span><span class="k2">)</span></span><br /><span class="source-code"><a href="http://www.allegro.cc/manual/al_start_thread"><span class="a">al_start_thread</span></a><span class="k2">(</span><span class="k2">)</span></span></p><p>Threads  :  17<br />Threads  :  16</p><p>So, all this crap is to know if I&#39;m doing something bad, or if it is a normal behavior. In case I&#39;m not doing something wrong, it&#39;s obvious that in my case would be better to use <span class="source-code"><a href="http://www.allegro.cc/manual/al_run_detached_thread"><span class="a">al_run_detached_thread</span></a><span class="k2">(</span><span class="k2">)</span></span>, since I don&#39;t need to close the thread for the main thread manually, am I right?.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 11 Jan 2012 01:38:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t think al_create_thread and al_destroy_thread do anything but allocate/free the memory. al_start_thread will start the thread and it ends when you return from it. Would that explain the numbers you are seeing?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 11 Jan 2012 04:55:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>As far as I can tell, al_create_thread actually spawns the thread, and it sits waiting for a condition variable fired by al_start_thread, then it launches into the user proc. I&#39;m not entirely sure why the thread api is set up that way, but it is.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 11 Jan 2012 06:00:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, probably it&#39;s the Task Manager not being precise, I thought it was a reliable tool. Here&#39;s a video showing the normal game.</p><p><div class="media-player youtube"><div style="margin: 1em 2em; background: url(/images/movie.png); width: 180px; height: 100px; text-align: center;"><a href="http://www.allegro.cc//www.youtube.com/watch?v=IyK7A_oAzhE" target="_blank"><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/object/a/4/a4d501cfc609dceddd0fffa109ee70d0.jpg" border="0" alt="video" title="Click to play video" /></a></div></div>	</p><p>And in this video some experiments that I can&#39;t understand.</p><p><div class="media-player youtube"><div style="margin: 1em 2em; background: url(/images/movie.png); width: 180px; height: 100px; text-align: center;"><a href="http://www.allegro.cc//www.youtube.com/watch?v=p2Go6ine7TM" target="_blank"><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/object/b/3/b392f96bf2258c5b61dd5fb426f94837.jpg" border="0" alt="video" title="Click to play video" /></a></div></div>	</p><p>PS: I&#39;m not creating another threads besides this, in my game, so, I think it could be Allegro, or the Task Manager not being precise.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 11 Jan 2012 17:46:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Have you tried <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653">Process Explorer</a>?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Wed, 11 Jan 2012 17:54:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wow, good tool.</p><p>It&#39;s showing the same information than the Task Manager, though. The game always starts with 15 threads and if I let it alone some time (maybe 5 min) drops to 12 threads, when I call <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_thread"><span class="a">al_create_thread</span></a><span class="k2">(</span><span class="k2">)</span></span> it creates another thread, the Process Explorer shows its Start Address is &quot;msvcrt.dll!_endthreadedx+0x29&quot;. </p><p>But I have just realized that such thread also disappear after some minutes, so there is no problem. Thanks for the tool Arthur.</p><p>Thanks to all.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 11 Jan 2012 18:54:02 +0000</pubDate>
	</item>
</rss>
