<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Thread Local Storage, part 1: Overview</title>
	<atom:link href="http://www.nynaeve.net/?feed=rss2&#038;p=180" rel="self" type="application/rss+xml" />
	<link>http://www.nynaeve.net/?p=180</link>
	<description>Adventures in Windows debugging and reverse engineering.</description>
	<lastBuildDate>Mon, 23 Jul 2012 05:58:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: Hugh</title>
		<link>http://www.nynaeve.net/?p=180&#038;cpage=1#comment-54673</link>
		<dc:creator>Hugh</dc:creator>
		<pubDate>Fri, 18 Dec 2009 12:56:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.nynaeve.net/?p=180#comment-54673</guid>
		<description>TLS is one way of providing per-thread non-volatile storage. Other OSs I have worked on (for example Stratus VOS) allowed one to declare per-thread static variables (a bit like _declspec(thread)).

The problem on Windows is performance, the _declspec(thread) seems costly, because each reference to such a var requires an overeahd of getting the TLS info.

I recently created some hand crafted code that we use to replace TLS in our own product&#039;s core library. This API provides the same thing (a per-thread pointer to some scratchpad data) but uses over 50% less CPU time (optimized x64 C code).

Although I&#039;m pleased with the algorithm (and it seems very solid) I do think that Microsoft could have done a better job with this, it really should be a lot less costly.

Thanks for an enlightening post though!

Hugh</description>
		<content:encoded><![CDATA[<p>TLS is one way of providing per-thread non-volatile storage. Other OSs I have worked on (for example Stratus VOS) allowed one to declare per-thread static variables (a bit like _declspec(thread)).</p>
<p>The problem on Windows is performance, the _declspec(thread) seems costly, because each reference to such a var requires an overeahd of getting the TLS info.</p>
<p>I recently created some hand crafted code that we use to replace TLS in our own product&#8217;s core library. This API provides the same thing (a per-thread pointer to some scratchpad data) but uses over 50% less CPU time (optimized x64 C code).</p>
<p>Although I&#8217;m pleased with the algorithm (and it seems very solid) I do think that Microsoft could have done a better job with this, it really should be a lot less costly.</p>
<p>Thanks for an enlightening post though!</p>
<p>Hugh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bobo</title>
		<link>http://www.nynaeve.net/?p=180&#038;cpage=1#comment-54175</link>
		<dc:creator>Bobo</dc:creator>
		<pubDate>Sun, 06 Dec 2009 00:05:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.nynaeve.net/?p=180#comment-54175</guid>
		<description>It&#039;s not the TEB, it&#039;s the KTHREAD data structure!</description>
		<content:encoded><![CDATA[<p>It&#8217;s not the TEB, it&#8217;s the KTHREAD data structure!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nynaeve &#187; Blog Archive &#187; Thread Local Storage, part 8: Wrap-up</title>
		<link>http://www.nynaeve.net/?p=180&#038;cpage=1#comment-19530</link>
		<dc:creator>Nynaeve &#187; Blog Archive &#187; Thread Local Storage, part 8: Wrap-up</dc:creator>
		<pubDate>Wed, 31 Oct 2007 16:36:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.nynaeve.net/?p=180#comment-19530</guid>
		<description>[...] Thread Local Storage, part 1: Overview  [...]</description>
		<content:encoded><![CDATA[<p>[...] Thread Local Storage, part 1: Overview  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nynaeve &#187; Blog Archive &#187; Thread Local Storage, part 2: Explicit TLS</title>
		<link>http://www.nynaeve.net/?p=180&#038;cpage=1#comment-19188</link>
		<dc:creator>Nynaeve &#187; Blog Archive &#187; Thread Local Storage, part 2: Explicit TLS</dc:creator>
		<pubDate>Tue, 23 Oct 2007 12:00:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.nynaeve.net/?p=180#comment-19188</guid>
		<description>[...] Nynaeve Adventures in Windows debugging and reverse engineering.      &#171; Thread Local Storage, part 1: Overview [...]</description>
		<content:encoded><![CDATA[<p>[...] Nynaeve Adventures in Windows debugging and reverse engineering.      &laquo; Thread Local Storage, part 1: Overview [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Skywing</title>
		<link>http://www.nynaeve.net/?p=180&#038;cpage=1#comment-19171</link>
		<dc:creator>Skywing</dc:creator>
		<pubDate>Tue, 23 Oct 2007 04:23:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.nynaeve.net/?p=180#comment-19171</guid>
		<description>Maybe.  It was nothing too special, mostly something to un-break ALT+TAB and fix the habit of the game to do bad things to the display&#039;s gamma correction.  It would probably be easier to just recompile the program, as id has released the source code for Quake 3.</description>
		<content:encoded><![CDATA[<p>Maybe.  It was nothing too special, mostly something to un-break ALT+TAB and fix the habit of the game to do bad things to the display&#8217;s gamma correction.  It would probably be easier to just recompile the program, as id has released the source code for Quake 3.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ac</title>
		<link>http://www.nynaeve.net/?p=180&#038;cpage=1#comment-19169</link>
		<dc:creator>ac</dc:creator>
		<pubDate>Tue, 23 Oct 2007 04:10:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.nynaeve.net/?p=180#comment-19169</guid>
		<description>I hope you will post the hacks you did for Quake 3 aswell sometime in the future</description>
		<content:encoded><![CDATA[<p>I hope you will post the hacks you did for Quake 3 aswell sometime in the future</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Skywing</title>
		<link>http://www.nynaeve.net/?p=180&#038;cpage=1#comment-19136</link>
		<dc:creator>Skywing</dc:creator>
		<pubDate>Mon, 22 Oct 2007 19:14:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.nynaeve.net/?p=180#comment-19136</guid>
		<description>Chris: Yeah, you shouldn&#039;t use TLS in work item routines.  More specifically, you can&#039;t assume that two calls to a work item routine will originate from the same thread pool thread, so you can&#039;t store persisted information across work item requests in TLS.  (You could conceivably use TLS only while you&#039;re in the context of the current work routine, but this is a fairly narrow use case.  It is safer to just avoid TLS entirely in work routines.)

Russell: Yes, although things change a bit in Vista (I&#039;ve got a planned post to talk about how things have evolved with how implicit TLS used to work pre-Vista and how it works post-Vista, so I&#039;ll hold off on saying more until those posts go live).</description>
		<content:encoded><![CDATA[<p>Chris: Yeah, you shouldn&#8217;t use TLS in work item routines.  More specifically, you can&#8217;t assume that two calls to a work item routine will originate from the same thread pool thread, so you can&#8217;t store persisted information across work item requests in TLS.  (You could conceivably use TLS only while you&#8217;re in the context of the current work routine, but this is a fairly narrow use case.  It is safer to just avoid TLS entirely in work routines.)</p>
<p>Russell: Yes, although things change a bit in Vista (I&#8217;ve got a planned post to talk about how things have evolved with how implicit TLS used to work pre-Vista and how it works post-Vista, so I&#8217;ll hold off on saying more until those posts go live).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Russell Osterlund</title>
		<link>http://www.nynaeve.net/?p=180&#038;cpage=1#comment-19130</link>
		<dc:creator>Russell Osterlund</dc:creator>
		<pubDate>Mon, 22 Oct 2007 18:04:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.nynaeve.net/?p=180#comment-19130</guid>
		<description>If one takes the time to step through the Window&#039;s loader, you will see that the loader code calls an internal routine, LdrpInitializeTls, before calling DbgBreakPoint (assuming the IsDebuggerPresent flag has been set).  LdrpInitializeTls then iterates through each DLL loaded at that point looking for the presence of a TLS directory entry in the PE file.  If one is found, only then will the TLS &quot;magic&quot; happen.  This is I think the reason for the &quot;annoying limitations&quot; you cited.</description>
		<content:encoded><![CDATA[<p>If one takes the time to step through the Window&#8217;s loader, you will see that the loader code calls an internal routine, LdrpInitializeTls, before calling DbgBreakPoint (assuming the IsDebuggerPresent flag has been set).  LdrpInitializeTls then iterates through each DLL loaded at that point looking for the presence of a TLS directory entry in the PE file.  If one is found, only then will the TLS &#8220;magic&#8221; happen.  This is I think the reason for the &#8220;annoying limitations&#8221; you cited.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Clark</title>
		<link>http://www.nynaeve.net/?p=180&#038;cpage=1#comment-19128</link>
		<dc:creator>Chris Clark</dc:creator>
		<pubDate>Mon, 22 Oct 2007 17:22:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.nynaeve.net/?p=180#comment-19128</guid>
		<description>I am not so familiar with TLS but I am wondering about how it works with thread pool threads?  With thread pool threads, you are basically running work items on threads that are reused.  In this case, I imagine that you cannot use thread local storage to share info &quot;across jobs&quot; because you don&#039;t actually know which thread the next job is going to run on.  Is this correct?  Not sure it is an interesting thing to talk about and I am certainly not completely informed about it but it popped into mind when reading this.  As always, great entry.</description>
		<content:encoded><![CDATA[<p>I am not so familiar with TLS but I am wondering about how it works with thread pool threads?  With thread pool threads, you are basically running work items on threads that are reused.  In this case, I imagine that you cannot use thread local storage to share info &#8220;across jobs&#8221; because you don&#8217;t actually know which thread the next job is going to run on.  Is this correct?  Not sure it is an interesting thing to talk about and I am certainly not completely informed about it but it popped into mind when reading this.  As always, great entry.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc Sherman</title>
		<link>http://www.nynaeve.net/?p=180&#038;cpage=1#comment-19124</link>
		<dc:creator>Marc Sherman</dc:creator>
		<pubDate>Mon, 22 Oct 2007 16:01:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.nynaeve.net/?p=180#comment-19124</guid>
		<description>Skywing,

This is the clearest description of the fs register I have read. That register was always semi-mysterious to me, but this article has made it very clear, thanks.

Looking forward to the rest of this series.

Marc</description>
		<content:encoded><![CDATA[<p>Skywing,</p>
<p>This is the clearest description of the fs register I have read. That register was always semi-mysterious to me, but this article has made it very clear, thanks.</p>
<p>Looking forward to the rest of this series.</p>
<p>Marc</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.591 seconds -->
