<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx</link><description>The WinRT programming environment, which is used to create Metro applications for Windows 8, replaces the old Win32 threading APIs such as CreateThread with a new ThreadPool::RunAsync API. This is generally a good thing (ThreadPool is better than CreateThread</description><dc:language>en</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx#10426196</link><pubDate>Sat, 15 Jun 2013 23:00:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10426196</guid><dc:creator>Alecazam</dc:creator><description>&lt;p&gt;I should clarify that my data was tied to thread id (and that is obtainable in a store app). &amp;nbsp;It&amp;#39;s just the thread id of the thread in the thread pool. &amp;nbsp; I could change the legacy code to reference off the thread (event) handle, but I wanted to keep that code unchanged.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10426196" width="1" height="1"&gt;</description></item><item><title>re: CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx#10426195</link><pubDate>Sat, 15 Jun 2013 22:52:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10426195</guid><dc:creator>Alecazam</dc:creator><description>&lt;p&gt;I had various routines that would obtain the current thread handle and pull up data off of that. &amp;nbsp;Since your emulation returns the thread back to the pool after the task completes, legacy code does not expect to see the same &amp;quot;thread handle&amp;quot; (emulated or real) appear until CloseHandle is called on the &amp;quot;thread handle&amp;quot;. &amp;nbsp;I&amp;#39;m only pointing out that the emulation isn&amp;#39;t quite right for legacy code. &amp;nbsp; I know it&amp;#39;s an event handle, I use the same approach. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10426195" width="1" height="1"&gt;</description></item><item><title>re: CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx#10392414</link><pubDate>Sun, 10 Feb 2013 01:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10392414</guid><dc:creator>cb</dc:creator><description>&lt;p&gt;Shawn, good stuff.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m curious why you don&amp;#39;t just use the Fls functions to replace Tls? &amp;nbsp;(eg. FlsAlloc for TlsAlloc). &amp;nbsp;Should be simpler and possibly faster.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10392414" width="1" height="1"&gt;</description></item><item><title>re: CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx#10383010</link><pubDate>Mon, 07 Jan 2013 23:36:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10383010</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><description>&lt;p&gt;Alecazam, I don&amp;#39;t understand your point here. &amp;nbsp;There is no such thing as a thread handle or thread ID in the Windows Store programming model. &amp;nbsp;All the Win32 APIs that return or accept such values are no longer supported, so these concepts no longer exist.&lt;/p&gt;
&lt;p&gt;This emulation code provides an emulation of one method (CreateThread) that does return a &amp;#39;thread handle&amp;#39;, but this is an emulated handle, not a real Win32 thread handle. &amp;nbsp;It works exactly like a real thread handle in that you can block on it using any of the Win32 wait APIs, and it will be signalled as soon as the &amp;#39;thread&amp;#39; has finished running, and you can CloseHandle on it when you are done using it, but it is not a real thread handle at the Win32 level, any more than this emulated CreateThread method creates a real Win32 thread &amp;nbsp;(actually, the &amp;#39;thread handle&amp;#39; returned by the CreateThread emulation is a Win32 manual reset event).&lt;/p&gt;
&lt;p&gt;This distinction is unimportant, however, because the emulated handle works correctly with the emulated CreateThread, and you do not have access to any of the various Win32 API methods that use real thread handles, so what difference does it make whether the returned value is a &amp;#39;real&amp;#39; thread handle or not?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10383010" width="1" height="1"&gt;</description></item><item><title>re: CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx#10379321</link><pubDate>Wed, 19 Dec 2012 06:18:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10379321</guid><dc:creator>Alecazam</dc:creator><description>&lt;p&gt;The code still needed a wait at the end of the async task to prevent the thread from being returned to the thread pool. &amp;nbsp;Otherwise elements that are tied to the thread handle or thread id get very confused when they see that same thread from the thread pool reused before CloseHandle has been hit. &amp;nbsp;If you try to make your emulation return a threadID, you&amp;#39;ll find that the code and suspended thread emulation become a lot more difficult (ie. Microsoft should be adding back this API).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10379321" width="1" height="1"&gt;</description></item><item><title>re: CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx#10373889</link><pubDate>Mon, 03 Dec 2012 01:52:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10373889</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><description>&lt;p&gt;There isn&amp;#39;t directly any such thing as a &amp;quot;thread handle&amp;quot; in WinRT - the actual threadpool task is a WinRT interface, not a Win32 handle at all. &amp;nbsp;The handle returned by my CreateThread emulation is part of the emulation layer, not directly part of the WinRT threadpool implementation. &amp;nbsp;So it&amp;#39;s up to my emulation layer to make this work however I see fit &amp;nbsp;(which in the case of this implementation was to copy the behavior of the Win32 CreateThread API).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10373889" width="1" height="1"&gt;</description></item><item><title>re: CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx#10373888</link><pubDate>Mon, 03 Dec 2012 01:47:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10373888</guid><dc:creator>Alecazam</dc:creator><description>&lt;p&gt;Thanks Shawn. &amp;nbsp;I didn&amp;#39;t realize that you could still wait on a thread handle under WinRT. &amp;nbsp;I&amp;#39;ve done the DuplicateHandle like you od, but we&amp;#39;ve been tracking an event with each thread handle. &amp;nbsp;When we get to a Wait, we wait on the event, and not the thread handle. &amp;nbsp;The thought was that the thread handle never signals, because it&amp;#39;s just thrown back into the pool.&lt;/p&gt;
&lt;p&gt;There&amp;#39;s still a need for the physical core count. &amp;nbsp;Logical cores is already obtained from GetNativeSystemInfo. &amp;nbsp;We have SIMD tasks that doesn&amp;#39;t benefit from the 2x threads. &amp;nbsp; The unfortunate aspect of a WinRT thread pool is not being able to require a physical core. &amp;nbsp;We need some hinting mechanism to request that.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10373888" width="1" height="1"&gt;</description></item><item><title>re: CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx#10373871</link><pubDate>Sun, 02 Dec 2012 20:53:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10373871</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><description>&lt;p&gt;Alcazam: my implementation handles the thread exit behavior just fine. The handle returned from the emulated CreateThread remains valid (and can be waited on) until the caller decides to call CloseHandle on it. &amp;nbsp;This isn&amp;#39;t tied to when the task completes (they are related because task completion will signal that handle, but it doesn&amp;#39;t close it, which is exactly the same as the original Win32 thread behavior).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10373871" width="1" height="1"&gt;</description></item><item><title>re: CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx#10373869</link><pubDate>Sun, 02 Dec 2012 20:13:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10373869</guid><dc:creator>Alecazam</dc:creator><description>&lt;p&gt;We&amp;#39;re having to implement a thread wrapper for legacy code as well. &amp;nbsp;Not only is it way too complex, but I see that your impl has the same problem as ours. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;The thread pool recycles the thread handle as soon as the task completes. &amp;nbsp;That differs from a real thread which stays valid until CloseHandle. &amp;nbsp;We have legacy code that is tracking it&amp;#39;s own data off the thread handle. &amp;nbsp;When it see the same thread handle appear, it thinks that thread is being used before it&amp;#39;s been released. &amp;nbsp;There needs to be something to prevent the thread/task from going back to the thread pool (yet another event/waitforsingleobjectex at the end of the task).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10373869" width="1" height="1"&gt;</description></item><item><title>re: CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx#10370457</link><pubDate>Wed, 21 Nov 2012 04:21:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10370457</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><description>&lt;p&gt;ESE:&lt;/p&gt;
&lt;p&gt;1) ThreadPool is a Windows kernel component, so yes, all native code. This functionality is exposed as a WinRT interface (ie a vtable containing pointers to code).&lt;/p&gt;
&lt;p&gt;2) I don&amp;#39;t work on the kernel/threading team who owns that decision, so I can&amp;#39;t comment on what they might decide to do in the future. I do know they had good reasons for the decisions made for Win8 Store apps, though.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10370457" width="1" height="1"&gt;</description></item></channel></rss>