<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Visual C++ Tips &#187; STILL_ACTIVE</title>
	<atom:link href="http://weseetips.com/tag/still_active/feed/" rel="self" type="application/rss+xml" />
	<link>http://weseetips.com</link>
	<description>Gold mine of Visual C++ tricks!</description>
	<lastBuildDate>Thu, 11 Mar 2010 09:09:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>How to check whether the thread is alive or dead?</title>
		<link>http://weseetips.com/2010/03/04/how-to-check-whether-the-thread-is-alive-or-dead/</link>
		<comments>http://weseetips.com/2010/03/04/how-to-check-whether-the-thread-is-alive-or-dead/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 16:39:18 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[check thread active]]></category>
		<category><![CDATA[GetExitCodeThread()]]></category>
		<category><![CDATA[STILL_ACTIVE]]></category>
		<category><![CDATA[thread active]]></category>
		<category><![CDATA[thread alive]]></category>
		<category><![CDATA[thread dead]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=1368</guid>
		<description><![CDATA[In multi-threaded environments, sometimes we need to check whether a given thread is alive or not. But how can we check it? Picture courtesy &#8211; Erica Marshall You can use the function &#8211; GetExitCodeThread(). If thread is alive, the function returns STILL_ACTIVE. Have a look at the code snippet. // Checks whether given thread is [...]]]></description>
			<content:encoded><![CDATA[<p>In multi-threaded environments, sometimes we need to check whether a given thread is alive or not. But how can we check it?</p>
<p><img class="alignnone size-full wp-image-1371" title="Thread-Alive" src="http://weseetips.com/wp-content/uploads/2010/03/Thread-Alive.jpg" alt="" width="500" height="333" /></p>
<p>Picture courtesy &#8211; <a href="http://www.flickr.com/photos/erica_marshall/2739537285/" target="_blank">Erica Marshall</a></p>
<p><img class="alignnone size-full wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.com/wp-content/uploads/2008/03/icon_howcanidoit.jpg" alt="" width="220" height="32" /><br />
You can use the function &#8211; <a href="http://msdn.microsoft.com/en-us/library/ms683190%28VS.85%29.aspx" target="_blank">GetExitCodeThread()</a>. If thread is alive, the function returns STILL_ACTIVE. Have a look at the code snippet.</p>
<pre>// Checks whether given thread is alive.
bool IsThreadAlive(const HANDLE hThread, bool&amp; bAlive )
{
 // Read thread's exit code.
 DWORD dwExitCode = 0;
 if( GetExitCodeThread(hThread, &amp;dwExitCode))
 {
 // if return code is STILL_ACTIVE,
 // then thread is live.
 bAlive = (dwExitCode == STILL_ACTIVE);
 return true;
 }

 // Check failed.
 return false;
}

void main()
{
 bool bAlive = false;
 if( IsThreadAlive( GetCurrentThread(), bAlive))
 {
 // IsThreadAlive is success.
 // Now check whether thread is alive.
 // It should, because its our main thread. <img src='http://weseetips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
 if( bAlive)
 {
 std::cout &lt;&lt; "Thread Alive!!!";
 }
 }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2010/03/04/how-to-check-whether-the-thread-is-alive-or-dead/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

