<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>wblog3</title>
	<atom:link href="http://wj32.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://wj32.wordpress.com</link>
	<description>information when you need it</description>
	<lastBuildDate>Tue, 17 Jan 2012 07:16:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='wj32.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/119d37b35da83d376b5d2ff33ee370b7?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>wblog3</title>
		<link>http://wj32.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://wj32.wordpress.com/osd.xml" title="wblog3" />
	<atom:link rel='hub' href='http://wj32.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Introducing WJ&#8217;s Backup</title>
		<link>http://wj32.wordpress.com/2011/12/10/introducing-wjs-backup/</link>
		<comments>http://wj32.wordpress.com/2011/12/10/introducing-wjs-backup/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 05:55:41 +0000</pubDate>
		<dc:creator>wj32</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[revision]]></category>

		<guid isPermaLink="false">http://wj32.wordpress.com/?p=368</guid>
		<description><![CDATA[Recently I became frustrated with Cobian Backup. It was the only free software I could find that: supported incremental backups, supported Volume Shadow Copy, and didn&#8217;t install a bunch of extra, useless startup entries and services. However, two things sucked: Incremental backups only seemed to work properly when it used the &#8220;archive&#8221; attribute. This meant [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=368&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I became frustrated with Cobian Backup. It was the only free software I could find that:</p>
<ol>
<li>supported incremental backups,</li>
<li>supported Volume Shadow Copy,</li>
<li>and didn&#8217;t install a bunch of extra, useless startup entries and services.</li>
</ol>
<p>However, two things sucked:</p>
<ol>
<li>Incremental backups only seemed to work properly when it used the &#8220;archive&#8221; attribute. This meant that it couldn&#8217;t recover from interrupted backups properly.</li>
<li>It didn&#8217;t provide any way of restoring files, so you had to go through the different .7z files and find the file you want to restore.</li>
</ol>
<p>So, I decided to create my own backup program: <a href="http://sourceforge.net/projects/wjbackup/">&#8220;WJ&#8217;s Backup&#8221;</a>. The possessive in the title is not to indicate some obsessive sense of ownership, but to emphasize the fact that the program was not developed with any other user&#8217;s perspective in mind.</p>
<p>Unlike most other backup programs I could find, WJ&#8217;s Backup maintains a database with file/directory metadata for each revision. It keeps file versions in a SVN-like way, but without diffs for file content (each new version is stored in full). 7-Zip compression is mandatory.</p>
<p><a href="http://sourceforge.net/projects/wjbackup/">Project page at SourceForge</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wj32.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wj32.wordpress.com/368/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wj32.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wj32.wordpress.com/368/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wj32.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wj32.wordpress.com/368/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wj32.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wj32.wordpress.com/368/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wj32.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wj32.wordpress.com/368/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wj32.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wj32.wordpress.com/368/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wj32.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wj32.wordpress.com/368/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=368&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wj32.wordpress.com/2011/12/10/introducing-wjs-backup/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dab4ece81a9b8832323ef2f73fcf12e?s=96&#38;d=identicon" medium="image">
			<media:title type="html">wj32</media:title>
		</media:content>
	</item>
		<item>
		<title>Power series of tan(x), cot(x), csc(x)</title>
		<link>http://wj32.wordpress.com/2011/10/30/power-series-of-tanx-cotx-cscx/</link>
		<comments>http://wj32.wordpress.com/2011/10/30/power-series-of-tanx-cotx-cscx/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 00:57:34 +0000</pubDate>
		<dc:creator>wj32</dc:creator>
				<category><![CDATA[mathematics]]></category>

		<guid isPermaLink="false">http://wj32.wordpress.com/?p=320</guid>
		<description><![CDATA[Here&#8217;s a little how-to on figuring out the power series of tan(x), cot(x) and csc(x). Start with the generating function for the Bernoulli numbers: Take only the even powers of t on the LHS: Put : Recall that and : That was pretty easy. How about tan and csc? Consider And finally,<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=320&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little how-to on figuring out the power series of tan(x), cot(x) and csc(x).</p>
<p>Start with the generating function for the Bernoulli numbers:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_k+%5Cfrac%7Bt%5Ek%7D%7Bk%21%7D+%3D+%5Cfrac%7Bt%7D%7Be%5Et-1%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;sum_{k=0}^{&#92;infty} B_k &#92;frac{t^k}{k!} = &#92;frac{t}{e^t-1}' title='&#92;displaystyle &#92;sum_{k=0}^{&#92;infty} B_k &#92;frac{t^k}{k!} = &#92;frac{t}{e^t-1}' class='latex' /></p>
<p>Take only the even powers of <em>t</em> on the LHS:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_k+%5Cfrac%7Bt%5Ek%7D%7Bk%21%7D+%2B+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_k+%5Cfrac%7B%28-t%29%5Ek%7D%7Bk%21%7D+%3D+%5Cfrac%7Bt%7D%7Be%5Et-1%7D+-+%5Cfrac%7Bt%7D%7Be%5E%7B-t%7D-1%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;sum_{k=0}^{&#92;infty} B_k &#92;frac{t^k}{k!} + &#92;sum_{k=0}^{&#92;infty} B_k &#92;frac{(-t)^k}{k!} = &#92;frac{t}{e^t-1} - &#92;frac{t}{e^{-t}-1}' title='&#92;displaystyle &#92;sum_{k=0}^{&#92;infty} B_k &#92;frac{t^k}{k!} + &#92;sum_{k=0}^{&#92;infty} B_k &#92;frac{(-t)^k}{k!} = &#92;frac{t}{e^t-1} - &#92;frac{t}{e^{-t}-1}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+2+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_%7B2k%7D+%5Cfrac%7Bt%5E%7B2k%7D%7D%7B%282k%29%21%7D+%3D+%5Cfrac%7Bt%5Cleft%28e%5E%7B-t%7D-e%5Et%5Cright%29%7D%7B%5Cleft%28e%5Et-1%5Cright%29%5Cleft%28e%5E%7B-t%7D-1%5Cright%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle 2 &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{t^{2k}}{(2k)!} = &#92;frac{t&#92;left(e^{-t}-e^t&#92;right)}{&#92;left(e^t-1&#92;right)&#92;left(e^{-t}-1&#92;right)}' title='&#92;displaystyle 2 &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{t^{2k}}{(2k)!} = &#92;frac{t&#92;left(e^{-t}-e^t&#92;right)}{&#92;left(e^t-1&#92;right)&#92;left(e^{-t}-1&#92;right)}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+%5Cfrac%7Bt%5Cleft%28e%5E%7B-%5Cfrac%7B1%7D%7B2%7D+t%7D%2Be%5E%7B%5Cfrac%7B1%7D%7B2%7D+t%7D%5Cright%29%5Cleft%28e%5E%7B-%5Cfrac%7B1%7D%7B2%7D+t%7D-e%5E%7B%5Cfrac%7B1%7D%7B2%7D+t%7D%5Cright%29%7D%7Be%5E%7B%5Cfrac%7B1%7D%7B2%7D+t%7D%5Cleft%28e%5E%7B%5Cfrac%7B1%7D%7B2%7D+t%7D-e%5E%7B-%5Cfrac%7B1%7D%7B2%7D+t%7D%5Cright%29e%5E%7B-%5Cfrac%7B1%7D%7B2%7D+t%7D%5Cleft%28e%5E%7B-%5Cfrac%7B1%7D%7B2%7D+t%7D-e%5E%7B%5Cfrac%7B1%7D%7B2%7D+t%7D%5Cright%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle = &#92;frac{t&#92;left(e^{-&#92;frac{1}{2} t}+e^{&#92;frac{1}{2} t}&#92;right)&#92;left(e^{-&#92;frac{1}{2} t}-e^{&#92;frac{1}{2} t}&#92;right)}{e^{&#92;frac{1}{2} t}&#92;left(e^{&#92;frac{1}{2} t}-e^{-&#92;frac{1}{2} t}&#92;right)e^{-&#92;frac{1}{2} t}&#92;left(e^{-&#92;frac{1}{2} t}-e^{&#92;frac{1}{2} t}&#92;right)}' title='&#92;displaystyle = &#92;frac{t&#92;left(e^{-&#92;frac{1}{2} t}+e^{&#92;frac{1}{2} t}&#92;right)&#92;left(e^{-&#92;frac{1}{2} t}-e^{&#92;frac{1}{2} t}&#92;right)}{e^{&#92;frac{1}{2} t}&#92;left(e^{&#92;frac{1}{2} t}-e^{-&#92;frac{1}{2} t}&#92;right)e^{-&#92;frac{1}{2} t}&#92;left(e^{-&#92;frac{1}{2} t}-e^{&#92;frac{1}{2} t}&#92;right)}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+%5Cfrac%7Bt%5Cleft%28e%5E%7B%5Cfrac%7B1%7D%7B2%7D+t%7D%2Be%5E%7B-%5Cfrac%7B1%7D%7B2%7D+t%7D%5Cright%29%7D%7Be%5E%7B%5Cfrac%7B1%7D%7B2%7D+t%7D-e%5E%7B-%5Cfrac%7B1%7D%7B2%7D+t%7D%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle = &#92;frac{t&#92;left(e^{&#92;frac{1}{2} t}+e^{-&#92;frac{1}{2} t}&#92;right)}{e^{&#92;frac{1}{2} t}-e^{-&#92;frac{1}{2} t}}' title='&#92;displaystyle = &#92;frac{t&#92;left(e^{&#92;frac{1}{2} t}+e^{-&#92;frac{1}{2} t}&#92;right)}{e^{&#92;frac{1}{2} t}-e^{-&#92;frac{1}{2} t}}' class='latex' /></p>
<p>Put <img src='http://s0.wp.com/latex.php?latex=t%3D2ix&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='t=2ix' title='t=2ix' class='latex' />:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+2+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_%7B2k%7D+%5Cfrac%7B%282ix%29%5E%7B2k%7D%7D%7B%282k%29%21%7D+%3D+%5Cfrac%7B2ix%5Cleft%28e%5E%7Bix%7D%2Be%5E%7B-ix%7D%5Cright%29%7D%7Be%5E%7Bix%7D-e%5E%7B-ix%7D%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle 2 &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(2ix)^{2k}}{(2k)!} = &#92;frac{2ix&#92;left(e^{ix}+e^{-ix}&#92;right)}{e^{ix}-e^{-ix}}' title='&#92;displaystyle 2 &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(2ix)^{2k}}{(2k)!} = &#92;frac{2ix&#92;left(e^{ix}+e^{-ix}&#92;right)}{e^{ix}-e^{-ix}}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_%7B2k%7D+%5Cfrac%7B%28-1%29%5Ek+4%5Ek+x%5E%7B2k-1%7D%7D%7B%282k%29%21%7D+%3D+%5Cfrac%7Bi%5Cleft%28e%5E%7Bix%7D%2Be%5E%7B-ix%7D%5Cright%29%7D%7Be%5E%7Bix%7D-e%5E%7B-ix%7D%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k x^{2k-1}}{(2k)!} = &#92;frac{i&#92;left(e^{ix}+e^{-ix}&#92;right)}{e^{ix}-e^{-ix}}' title='&#92;displaystyle &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k x^{2k-1}}{(2k)!} = &#92;frac{i&#92;left(e^{ix}+e^{-ix}&#92;right)}{e^{ix}-e^{-ix}}' class='latex' /></p>
<p>Recall that <img src='http://s0.wp.com/latex.php?latex=%5Csin+x+%3D+%5Cfrac%7Be%5E%7Bix%7D-e%5E%7B-ix%7D%7D%7B2i%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sin x = &#92;frac{e^{ix}-e^{-ix}}{2i}' title='&#92;sin x = &#92;frac{e^{ix}-e^{-ix}}{2i}' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Ccos+x+%3D+%5Cfrac%7Be%5E%7Bix%7D%2Be%5E%7B-ix%7D%7D%7B2%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;cos x = &#92;frac{e^{ix}+e^{-ix}}{2}' title='&#92;cos x = &#92;frac{e^{ix}+e^{-ix}}{2}' class='latex' />:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7B%5Ccos+x%7D%7B%5Csin+x%7D+%3D+%5Ccot+x+%3D+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_%7B2k%7D+%5Cfrac%7B%28-1%29%5Ek+4%5Ek+x%5E%7B2k-1%7D%7D%7B%282k%29%21%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;frac{&#92;cos x}{&#92;sin x} = &#92;cot x = &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k x^{2k-1}}{(2k)!}' title='&#92;displaystyle &#92;frac{&#92;cos x}{&#92;sin x} = &#92;cot x = &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k x^{2k-1}}{(2k)!}' class='latex' /></p>
<p>That was pretty easy. How about tan and csc?</p>
<p>Consider</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Ccot+x+-+2%5Ccot+2x+%3D+%5Ccot+x+-+%5Cfrac%7B%5Ccot%5E2+x+-+1%7D%7B%5Ccot+x%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;cot x - 2&#92;cot 2x = &#92;cot x - &#92;frac{&#92;cot^2 x - 1}{&#92;cot x}' title='&#92;displaystyle &#92;cot x - 2&#92;cot 2x = &#92;cot x - &#92;frac{&#92;cot^2 x - 1}{&#92;cot x}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+%5Cfrac%7B1%7D%7B%5Ccot+x%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle = &#92;frac{1}{&#92;cot x}' title='&#92;displaystyle = &#92;frac{1}{&#92;cot x}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+%5Ctan+x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle = &#92;tan x' title='&#92;displaystyle = &#92;tan x' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Ctan+x+%3D+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_%7B2k%7D+%5Cfrac%7B%28-1%29%5Ek+4%5Ek+x%5E%7B2k-1%7D%7D%7B%282k%29%21%7D+-+2%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_%7B2k%7D+%5Cfrac%7B%28-1%29%5Ek+4%5Ek+2%5E%7B2k-1%7D+x%5E%7B2k-1%7D%7D%7B%282k%29%21%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;tan x = &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k x^{2k-1}}{(2k)!} - 2&#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k 2^{2k-1} x^{2k-1}}{(2k)!}' title='&#92;displaystyle &#92;tan x = &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k x^{2k-1}}{(2k)!} - 2&#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k 2^{2k-1} x^{2k-1}}{(2k)!}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Ctan+x+%3D+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_%7B2k%7D+%5Cfrac%7B%28-1%29%5Ek+4%5Ek+%281-4%5Ek%29+x%5E%7B2k-1%7D%7D%7B%282k%29%21%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;tan x = &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k (1-4^k) x^{2k-1}}{(2k)!}' title='&#92;displaystyle &#92;tan x = &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k (1-4^k) x^{2k-1}}{(2k)!}' class='latex' /></p>
<p>And finally,</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Ccot+x+-+%5Ccot+2x+%3D+%5Ccot+x+-+%5Cfrac%7B%5Ccot%5E2+x+-+1%7D%7B2%5Ccot+x%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;cot x - &#92;cot 2x = &#92;cot x - &#92;frac{&#92;cot^2 x - 1}{2&#92;cot x}' title='&#92;displaystyle &#92;cot x - &#92;cot 2x = &#92;cot x - &#92;frac{&#92;cot^2 x - 1}{2&#92;cot x}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+%5Cfrac%7B%5Ccsc%5E2+x%7D%7B2%5Ccot+x%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle = &#92;frac{&#92;csc^2 x}{2&#92;cot x}' title='&#92;displaystyle = &#92;frac{&#92;csc^2 x}{2&#92;cot x}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+%5Cfrac%7B1%7D%7B2+%5Csin+x+%5Ccos+x%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle = &#92;frac{1}{2 &#92;sin x &#92;cos x}' title='&#92;displaystyle = &#92;frac{1}{2 &#92;sin x &#92;cos x}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+%5Ccsc+2x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle = &#92;csc 2x' title='&#92;displaystyle = &#92;csc 2x' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Ccsc+x+%3D+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_%7B2k%7D+%5Cfrac%7B%28-1%29%5Ek+4%5Ek+x%5E%7B2k-1%7D%7D%7B2%5E%7B2k-1%7D+%282k%29%21%7D+-+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_%7B2k%7D+%5Cfrac%7B%28-1%29%5Ek+4%5Ek+x%5E%7B2k-1%7D%7D%7B%282k%29%21%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;csc x = &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k x^{2k-1}}{2^{2k-1} (2k)!} - &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k x^{2k-1}}{(2k)!}' title='&#92;displaystyle &#92;csc x = &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k x^{2k-1}}{2^{2k-1} (2k)!} - &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k 4^k x^{2k-1}}{(2k)!}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Ccsc+x+%3D+%5Csum_%7Bk%3D0%7D%5E%7B%5Cinfty%7D+B_%7B2k%7D+%5Cfrac%7B%28-1%29%5Ek+%282-4%5Ek%29+x%5E%7B2k-1%7D%7D%7B%282k%29%21%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;csc x = &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k (2-4^k) x^{2k-1}}{(2k)!}' title='&#92;displaystyle &#92;csc x = &#92;sum_{k=0}^{&#92;infty} B_{2k} &#92;frac{(-1)^k (2-4^k) x^{2k-1}}{(2k)!}' class='latex' /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wj32.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wj32.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wj32.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wj32.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wj32.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wj32.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wj32.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wj32.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wj32.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wj32.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wj32.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wj32.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wj32.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wj32.wordpress.com/320/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=320&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wj32.wordpress.com/2011/10/30/power-series-of-tanx-cotx-cscx/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dab4ece81a9b8832323ef2f73fcf12e?s=96&#38;d=identicon" medium="image">
			<media:title type="html">wj32</media:title>
		</media:content>
	</item>
		<item>
		<title>Thread-safe one-time initialization</title>
		<link>http://wj32.wordpress.com/2011/03/04/thread-safe-one-time-initialization/</link>
		<comments>http://wj32.wordpress.com/2011/03/04/thread-safe-one-time-initialization/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 09:43:52 +0000</pubDate>
		<dc:creator>wj32</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[multithreading]]></category>

		<guid isPermaLink="false">http://wj32.wordpress.com/?p=313</guid>
		<description><![CDATA[Not thread-safe Disadvantages: Not thread-safe Thread-safe (locking, double-checked) Advantages: Thread-safe Disadvantages: Lock overhead More code Thread-safe (custom) Advantages: Thread-safe Less overhead Disadvantages: More code Created object may need to be destroyed<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=313&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Not thread-safe</strong></p>
<p><pre class="brush: cpp;">
BOOLEAN initialized = FALSE;
OBJECT object = NULL;

DoSomething()
{
    if (!initialized)
    {
        object = Create();
        initialized = TRUE;
    }
    
    // Use object.
}
</pre></p>
<p>Disadvantages:</p>
<ul>
<li>Not thread-safe</li>
</ul>
<p><strong>Thread-safe (locking, double-checked)</strong></p>
<p><pre class="brush: cpp;">
BOOLEAN initialized = FALSE;
OBJECT object = NULL;
LOCK lock = LOCK_INIT;

DoSomething()
{
    if (!initialized)
    {
        AcquireLock(&amp;lock);
        
        if (!initialized)
        {
            object = Create();
            MemoryBarrier();
            initialized = TRUE;
        }
        
        ReleaseLock(&amp;lock);
    }
    
    // Use object.
}
</pre></p>
<p>Advantages:</p>
<ul>
<li>Thread-safe</li>
</ul>
<p>Disadvantages:</p>
<ul>
<li>Lock overhead</li>
<li>More code</li>
</ul>
<p><strong>Thread-safe (custom)</strong></p>
<p><pre class="brush: cpp;">
OBJECT object = NULL;

DoSomething()
{
    OBJECT localObject;
    OBJECT newObject;
    
    localObject = object;
    
    if (!localObject)
    {
        newObject = Create();
        
        // Try to store the created object.
        localObject = InterlockedCompareExchangePointer(
            &amp;object,
            newObject,
            NULL
            );
        
        if (!localObject)
        {
            // Success.
            localObject = newObject;
        }
        else
        {
            // Some other thread already stored the object.
            Destroy(newObject);
        }
    }
    
    return localObject;
}
</pre></p>
<p>Advantages:</p>
<ul>
<li>Thread-safe</li>
<li>Less overhead</li>
</ul>
<p>Disadvantages:</p>
<ul>
<li>More code</li>
<li>Created object may need to be destroyed</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wj32.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wj32.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wj32.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wj32.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wj32.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wj32.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wj32.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wj32.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wj32.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wj32.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wj32.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wj32.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wj32.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wj32.wordpress.com/313/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=313&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wj32.wordpress.com/2011/03/04/thread-safe-one-time-initialization/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dab4ece81a9b8832323ef2f73fcf12e?s=96&#38;d=identicon" medium="image">
			<media:title type="html">wj32</media:title>
		</media:content>
	</item>
		<item>
		<title>PAE patch updated for Windows 7 SP1</title>
		<link>http://wj32.wordpress.com/2011/02/23/pae-patch-updated-for-windows-7-sp1/</link>
		<comments>http://wj32.wordpress.com/2011/02/23/pae-patch-updated-for-windows-7-sp1/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 08:45:00 +0000</pubDate>
		<dc:creator>wj32</dc:creator>
				<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://wj32.wordpress.com/?p=307</guid>
		<description><![CDATA[This patch allows you to use more than 3/4GB of RAM on an x86 Windows system. Works on Vista and 7, has been tested on Windows Vista SP2, Windows 7 SP0 and Windows 7 SP1. Instructions and source code included. Download: http://www.mediafire.com/?01x25z8sqvbbzfz Note: I do not offer any support for this. If this did not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=307&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This patch allows you to use more than 3/4GB of RAM on an x86 Windows system. Works on Vista and 7, has been tested on Windows Vista SP2, Windows 7 SP0 and Windows 7 SP1. Instructions and source code included.</p>
<p><strong>Download:</strong> <a href="http://www.mediafire.com/?01x25z8sqvbbzfz">http://www.mediafire.com/?01x25z8sqvbbzfz</a></p>
<p>Note: I do not offer <strong>any</strong> support for this. If this did not work for you, either:</p>
<ul>
<li>You cannot follow instructions correctly, or</li>
<li>You cannot use more than 4GB of physical memory on 32-bit Windows due to hardware/software conflicts.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wj32.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wj32.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wj32.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wj32.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wj32.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wj32.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wj32.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wj32.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wj32.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wj32.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wj32.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wj32.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wj32.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wj32.wordpress.com/307/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=307&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wj32.wordpress.com/2011/02/23/pae-patch-updated-for-windows-7-sp1/feed/</wfw:commentRss>
		<slash:comments>48</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dab4ece81a9b8832323ef2f73fcf12e?s=96&#38;d=identicon" medium="image">
			<media:title type="html">wj32</media:title>
		</media:content>
	</item>
		<item>
		<title>Fast CRC32 in Assembly</title>
		<link>http://wj32.wordpress.com/2010/09/19/fast-crc32-in-assembly/</link>
		<comments>http://wj32.wordpress.com/2010/09/19/fast-crc32-in-assembly/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 00:33:19 +0000</pubDate>
		<dc:creator>wj32</dc:creator>
				<category><![CDATA[Assembly]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[crc32]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://wj32.wordpress.com/?p=289</guid>
		<description><![CDATA[Timings on 768 bytes, 1,000,000 times: Assembly: 1722ms C (same algorithm, MSVC, -O2): 2099ms RtlComputeCrc32: 2033ms Timings on 2,097,152 bytes, 1,000 times: Assembly: 5375ms C: 5892ms RtlComputeCrc32: 5608ms It&#8217;s pretty fast, but nowhere as fast as an implementation that processes the data in 16-bit quantities. Note: Crc32Table not included.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=289&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Timings on 768 bytes, 1,000,000 times:</p>
<p>Assembly: 1722ms<br />
C (same algorithm, MSVC, -O2): 2099ms<br />
RtlComputeCrc32: 2033ms</p>
<p>Timings on 2,097,152 bytes, 1,000 times:</p>
<p>Assembly: 5375ms<br />
C: 5892ms<br />
RtlComputeCrc32: 5608ms</p>
<p>It&#8217;s pretty fast, but nowhere as fast as an implementation that processes the data in 16-bit quantities.</p>
<p>Note: Crc32Table not included.</p>
<p><pre class="brush: cpp;">__declspec(naked) unsigned long __cdecl crc32(unsigned long crc, char *buf, size_t len)
{
    __asm
    {
        push    esi

        mov     eax, [esp+0x8+0x0] // crc
        mov     ecx, [esp+0x8+0x8] // len
        mov     esi, [esp+0x8+0x4] // buf

        xor     edx, edx // all bits but lowest 8 are kept clear for use as the index
        jecxz   done
        not     eax

        // while (len--)
        //     crc = (crc &gt;&gt; 8 ) ^ table[(crc ^ *buf++) &amp; 0xff]
loop_start:
        mov     dl, [esi] // 1
        inc     esi // 1
        xor     dl, al // 2 (dl)
        shr     eax, 8 // 2
        xor     eax, [Crc32Table+edx*4] // 3 (eax, edx)

        sub     ecx, 1 // 4
        jnz     loop_start // 4

        not     eax
done:
        pop     esi
        ret
    }
}</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wj32.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wj32.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wj32.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wj32.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wj32.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wj32.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wj32.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wj32.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wj32.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wj32.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wj32.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wj32.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wj32.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wj32.wordpress.com/289/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=289&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wj32.wordpress.com/2010/09/19/fast-crc32-in-assembly/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dab4ece81a9b8832323ef2f73fcf12e?s=96&#38;d=identicon" medium="image">
			<media:title type="html">wj32</media:title>
		</media:content>
	</item>
		<item>
		<title>The NT &#8220;reserve object&#8221;</title>
		<link>http://wj32.wordpress.com/2010/07/18/the-nt-reserve-object/</link>
		<comments>http://wj32.wordpress.com/2010/07/18/the-nt-reserve-object/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 09:53:03 +0000</pubDate>
		<dc:creator>wj32</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[reversing]]></category>
		<category><![CDATA[undocumented]]></category>

		<guid isPermaLink="false">http://wj32.wordpress.com/?p=280</guid>
		<description><![CDATA[Windows 7 introduced two new object types: UserApcReserve and IoCompletionReserve. What do these object types have in common? They&#8217;re both created using NtAllocateReserveObject. If we look inside this system call we can see that the third argument is an index into two arrays, PspMemoryReserveObjectSizes and PspMemoryReserveObjectTypes. Notice that PspInitPhase0 creates a set number (currently two) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=280&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Windows 7 introduced two new object types: UserApcReserve and IoCompletionReserve. What do these object types have in common? They&#8217;re both created using NtAllocateReserveObject. If we look inside this system call we can see that the third argument is an index into two arrays, PspMemoryReserveObjectSizes and PspMemoryReserveObjectTypes. Notice that PspInitPhase0 creates a set number (currently two) of object types, drawing the names from another array: PspMemoryReserveObjectNames. Here&#8217;s my reversed definition of NtAllocateReserveObject:</p>
<p><pre class="brush: cpp;">#define USER_APC_RESERVE_TYPE 0
#define IO_COMPLETION_RESERVE_TYPE 1

NTSYSCALLAPI
NTSTATUS
NTAPI
NtAllocateReserveObject(
    __out PHANDLE MemoryReserveHandle,
    __in_opt POBJECT_ATTRIBUTES ObjectAttributes,
    __in ULONG Type
    );</pre></p>
<p>Two new system calls take advantage of the UserApcReserve object and IoCompletionReserve object: NtQueueApcThreadEx and NtSetIoCompletionEx, respectively. In NtQueueApcThreadEx we can see that if a user APC reserve handle/object is supplied, the function uses the space allocated for that object to store the APC, instead of allocating from the pool. Similarly NtSetIoCompletionEx uses the I/O completion reserve object&#8217;s already allocated space to store the I/O completion mini-packet, instead of allocating from the pool. It is now clear what the purpose of these reserve objects are: to allow processes to reserve memory before performing certain system calls in order to avoid out-of-memory problems occurring at bad spots (or critical code). Here&#8217;s my reversed definitions for the two system calls:</p>
<p><pre class="brush: cpp;">NTSYSCALLAPI
NTSTATUS
NTAPI
NtQueueApcThreadEx(
    __in HANDLE ThreadHandle,
    __in_opt HANDLE UserApcReserveHandle,
    __in PPS_APC_ROUTINE ApcRoutine,
    __in_opt PVOID ApcArgument1,
    __in_opt PVOID ApcArgument2,
    __in_opt PVOID ApcArgument3
    );

NTSYSCALLAPI
NTSTATUS
NTAPI
NtSetIoCompletionEx(
    __in HANDLE IoCompletionHandle,
    __in HANDLE IoCompletionReserveHandle,
    __in PVOID KeyContext,
    __in_opt PVOID ApcContext,
    __in NTSTATUS IoStatus,
    __in ULONG_PTR IoStatusInformation
    );</pre></p>
<p>Note that NtQueueApcThread now calls NtQueueApcThreadEx, which is why the reserve object is optional.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wj32.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wj32.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wj32.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wj32.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wj32.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wj32.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wj32.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wj32.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wj32.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wj32.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wj32.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wj32.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wj32.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wj32.wordpress.com/280/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=280&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wj32.wordpress.com/2010/07/18/the-nt-reserve-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dab4ece81a9b8832323ef2f73fcf12e?s=96&#38;d=identicon" medium="image">
			<media:title type="html">wj32</media:title>
		</media:content>
	</item>
		<item>
		<title>PAE patch updated for Windows 7</title>
		<link>http://wj32.wordpress.com/2010/05/04/pae-patch-updated-for-windows-7/</link>
		<comments>http://wj32.wordpress.com/2010/05/04/pae-patch-updated-for-windows-7/#comments</comments>
		<pubDate>Tue, 04 May 2010 02:53:11 +0000</pubDate>
		<dc:creator>wj32</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[pae]]></category>
		<category><![CDATA[patch]]></category>

		<guid isPermaLink="false">http://wj32.wordpress.com/?p=277</guid>
		<description><![CDATA[Note: An updated version for Windows 7 SP1 is available. This patch allows you to use more than 3/4GB of RAM on an x86 Windows system. Works on Vista and 7, has been tested on Windows Vista SP2 and Windows 7. Instructions and source code included. Download: http://www.mediafire.com/file/tgjjmhnnm2c/PatchPae.zip<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=277&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Note: An <a href="http://wj32.wordpress.com/2011/02/23/pae-patch-updated-for-windows-7-sp1/">updated version for Windows 7 SP1</a> is available.</strong></p>
<p>This patch allows you to use more than 3/4GB of RAM on an x86 Windows system. Works on Vista and 7, has been tested on Windows Vista SP2 and Windows 7. Instructions and source code included.</p>
<p><strong>Download:</strong> <a href="http://www.mediafire.com/file/tgjjmhnnm2c/PatchPae.zip">http://www.mediafire.com/file/tgjjmhnnm2c/PatchPae.zip</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wj32.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wj32.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wj32.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wj32.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wj32.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wj32.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wj32.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wj32.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wj32.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wj32.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wj32.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wj32.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wj32.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wj32.wordpress.com/277/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=277&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wj32.wordpress.com/2010/05/04/pae-patch-updated-for-windows-7/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dab4ece81a9b8832323ef2f73fcf12e?s=96&#38;d=identicon" medium="image">
			<media:title type="html">wj32</media:title>
		</media:content>
	</item>
		<item>
		<title>HOWTO: Use I_QueryTagInformation</title>
		<link>http://wj32.wordpress.com/2010/03/30/howto-use-i_querytaginformation/</link>
		<comments>http://wj32.wordpress.com/2010/03/30/howto-use-i_querytaginformation/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 08:22:18 +0000</pubDate>
		<dc:creator>wj32</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[undocumented]]></category>

		<guid isPermaLink="false">http://wj32.wordpress.com/?p=271</guid>
		<description><![CDATA[Process Explorer 12 includes a new feature whereby you can view service names associated with threads. To find out how this works, read this article by Alex Ionescu. You won&#8217;t be completely satisfied, though. You still don&#8217;t know how to use I_QueryTagInformation. First step: Getting the service tag for a thread This is simple; use [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=271&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Process Explorer 12 includes a new feature whereby you can view service names associated with threads. To find out how this works, read <a href="http://www.alex-ionescu.com/?p=52">this article by Alex Ionescu</a>. You won&#8217;t be completely satisfied, though. You still don&#8217;t know how to use I_QueryTagInformation.</p>
<p><strong>First step: Getting the service tag for a thread</strong><br />
This is simple; use NtQueryInformationThread to get the thread&#8217;s TEB address, then read the SubProcessTag from the TEB:</p>
<p><pre class="brush: cpp;">THREAD_BASIC_INFORMATION basicInfo;
PVOID subProcessTag;

NtQueryInformationThread(your_thread_handle, ThreadBasicInformation, &amp;basicInfo, sizeof(basicInfo), NULL);
NtReadVirtualMemory(handle_to_the_process_containing_the_thread, (PVOID)((ULONG_PTR)basicInfo.TebBaseAddress + FIELD_OFFSET(TEB, SubProcessTag)), &amp;subProcessTag, sizeof(PVOID), NULL);

// If you don't have the full TEB definition, here are the offsets (replace the FIELD_OFFSET invocation with these):
// x86: 0xf60
// x64: 0x1720

// You now have the service tag in subProcessTag.
</pre></p>
<p><strong>Second step: Using I_QueryTagInformation</strong><br />
I_QueryTagInformation is located in advapi32.dll. Here&#8217;s what I&#8217;ve reverse-engineered from looking at advapi32.dll and services.exe:</p>
<p><pre class="brush: cpp;">typedef enum _SC_SERVICE_TAG_QUERY_TYPE
{
    ServiceNameFromTagInformation = 1,
    ServiceNamesReferencingModuleInformation,
    ServiceNameTagMappingInformation
} SC_SERVICE_TAG_QUERY_TYPE, *PSC_SERVICE_TAG_QUERY_TYPE;

typedef struct _SC_SERVICE_TAG_QUERY
{
    ULONG ProcessId;
    ULONG ServiceTag;
    ULONG Unknown;
    PVOID Buffer;
} SC_SERVICE_TAG_QUERY, *PSC_SERVICE_TAG_QUERY;

typedef ULONG (NTAPI *_I_QueryTagInformation)(
    __in PVOID Unknown,
    __in SC_SERVICE_TAG_QUERY_TYPE QueryType,
    __inout PSC_SERVICE_TAG_QUERY Query
    );
</pre></p>
<p>The usage is fairly obvious: you want the service name for the service tag (ServiceNameFromTagInformation), you fill in the SC_SERVICE_TAG_QUERY structure, and you call I_QueryTagInformation:</p>
<p><pre class="brush: cpp;">_I_QueryTagInformation I_QueryTagInformation;
SC_SERVICE_TAG_QUERY query;

I_QueryTagInformation = GetProcAddress(GetModuleHandle(L&quot;advapi32.dll&quot;), &quot;I_QueryTagInformation&quot;);

if (I_QueryTagInformation)
{
    query.ProcessId = (ULONG)your_process_ID;
    query.ServiceTag = (ULONG)subProcessTag;
    query.Unknown = 0;
    query.Buffer = NULL;
    
    I_QueryTagInformation(NULL, ServiceNameFromTagInformation, &amp;query);
    
    wprintf(L&quot;Service name: %s\n&quot;, query.Buffer);
    LocalFree(query.Buffer);
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wj32.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wj32.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wj32.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wj32.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wj32.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wj32.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wj32.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wj32.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wj32.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wj32.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wj32.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wj32.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wj32.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wj32.wordpress.com/271/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=271&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wj32.wordpress.com/2010/03/30/howto-use-i_querytaginformation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dab4ece81a9b8832323ef2f73fcf12e?s=96&#38;d=identicon" medium="image">
			<media:title type="html">wj32</media:title>
		</media:content>
	</item>
		<item>
		<title>Get the image file name of any process from any user on Vista and above</title>
		<link>http://wj32.wordpress.com/2010/03/30/get-the-image-file-name-of-any-process-from-any-user-on-vista-and-above/</link>
		<comments>http://wj32.wordpress.com/2010/03/30/get-the-image-file-name-of-any-process-from-any-user-on-vista-and-above/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 08:02:27 +0000</pubDate>
		<dc:creator>wj32</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[nt]]></category>
		<category><![CDATA[undocumented]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://wj32.wordpress.com/?p=267</guid>
		<description><![CDATA[On Vista and above there is an information class for NtQuerySystemInformation which I call SystemProcessImageNameInformation (88). (Note that I reverse-engineered this, so it is probably not the correct name for the information class.) The structure definition is below: This information class allows you to get the image file name of any process, regardless of your [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=267&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>On Vista and above there is an information class for NtQuerySystemInformation which I call SystemProcessImageNameInformation (88). (Note that I reverse-engineered this, so it is probably not the correct name for the information class.) The structure definition is below:</p>
<p><pre class="brush: cpp;">typedef struct _SYSTEM_PROCESS_IMAGE_NAME_INFORMATION
{
    HANDLE ProcessId;
    UNICODE_STRING ImageName;
} SYSTEM_PROCESS_IMAGE_NAME_INFORMATION, *PSYSTEM_PROCESS_IMAGE_NAME_INFORMATION;
</pre></p>
<p>This information class allows you to get the image file name of any process, regardless of your user, privileges, or access to the process. Usage:</p>
<p><pre class="brush: cpp;">NTSTATUS status;
PVOID buffer;
SYSTEM_PROCESS_IMAGE_NAME_INFORMATION info;

buffer = malloc(0x100);
info.ProcessId = WhateverTheProcessIdIs;
info.ImageName.Length = 0;
info.ImageName.MaximumLength = (USHORT)0x100;
info.ImageName.Buffer = buffer;

status = NtQuerySystemInformation(88, &amp;info, sizeof(info), NULL);

if (status == STATUS_INFO_LENGTH_MISMATCH)
{
    // Our buffer was too small. The required buffer length is stored in MaximumLength.
    free(buffer);
    buffer = malloc(info.ImageName.MaximumLength);
    info.ImageName.Buffer = buffer;
    status = NtQuerySystemInformation(88, &amp;info, sizeof(info), NULL);
}

if (NT_SUCCESS(status))
{
    wprintf(L&quot;File name: %.*s\n&quot;, info.ImageName.Length / 2, info.ImageName.Buffer);
}

free(buffer);
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wj32.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wj32.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wj32.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wj32.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wj32.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wj32.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wj32.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wj32.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wj32.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wj32.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wj32.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wj32.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wj32.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wj32.wordpress.com/267/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=267&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wj32.wordpress.com/2010/03/30/get-the-image-file-name-of-any-process-from-any-user-on-vista-and-above/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dab4ece81a9b8832323ef2f73fcf12e?s=96&#38;d=identicon" medium="image">
			<media:title type="html">wj32</media:title>
		</media:content>
	</item>
		<item>
		<title>Fast reader-writer lock in C</title>
		<link>http://wj32.wordpress.com/2010/01/23/fast-reader-writer-lock-in-c/</link>
		<comments>http://wj32.wordpress.com/2010/01/23/fast-reader-writer-lock-in-c/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 00:54:20 +0000</pubDate>
		<dc:creator>wj32</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[reader-writer]]></category>

		<guid isPermaLink="false">http://wj32.wordpress.com/?p=261</guid>
		<description><![CDATA[I ported my fast reader-writer lock from C# to C for Process Hacker 2. Here it is.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=261&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I ported my fast reader-writer lock from C# to C for Process Hacker 2. Here it is.</p>
<p><pre class="brush: cpp;">
#include &lt;windows.h&gt;
#include &lt;intrin.h&gt;

// Put this in a header file.
typedef struct _PH_FAST_LOCK
{
    ULONG Value;
    HANDLE ExclusiveWakeEvent;
    HANDLE SharedWakeEvent;
} PH_FAST_LOCK, *PPH_FAST_LOCK;

#define PH_LOCK_OWNED 0x1
#define PH_LOCK_EXCLUSIVE_WAKING 0x2

#define PH_LOCK_SHARED_OWNERS_SHIFT 2
#define PH_LOCK_SHARED_OWNERS_MASK 0x3ff
#define PH_LOCK_SHARED_OWNERS_INC 0x4

#define PH_LOCK_SHARED_WAITERS_SHIFT 12
#define PH_LOCK_SHARED_WAITERS_MASK 0x3ff
#define PH_LOCK_SHARED_WAITERS_INC 0x1000

#define PH_LOCK_EXCLUSIVE_WAITERS_SHIFT 22
#define PH_LOCK_EXCLUSIVE_WAITERS_MASK 0x3ff
#define PH_LOCK_EXCLUSIVE_WAITERS_INC 0x400000

#define PH_LOCK_EXCLUSIVE_MASK \
    (PH_LOCK_EXCLUSIVE_WAKING | \
    (PH_LOCK_EXCLUSIVE_WAITERS_MASK &lt;&lt; PH_LOCK_EXCLUSIVE_WAITERS_SHIFT))

static ULONG PhLockSpinCount;

// Call this method BEFORE using any of the other functions.
VOID PhFastLockInitialization()
{
    SYSTEM_INFO systemInfo;

    GetSystemInfo(&amp;systemInfo);

    if (systemInfo.dwNumberOfProcessors &gt; 1)
        PhLockSpinCount = 4000;
    else
        PhLockSpinCount = 0;
}

VOID PhInitializeFastLock(
    __out PPH_FAST_LOCK FastLock
    )
{
    FastLock-&gt;Value = 0;
    FastLock-&gt;ExclusiveWakeEvent = NULL;
    FastLock-&gt;SharedWakeEvent = NULL;
}

VOID PhDeleteFastLock(
    __inout PPH_FAST_LOCK FastLock
    )
{
    if (FastLock-&gt;ExclusiveWakeEvent)
    {
        CloseHandle(FastLock-&gt;ExclusiveWakeEvent);
        FastLock-&gt;ExclusiveWakeEvent = NULL;
    }

    if (FastLock-&gt;SharedWakeEvent)
    {
        CloseHandle(FastLock-&gt;SharedWakeEvent);
        FastLock-&gt;SharedWakeEvent = NULL;
    }
}

#ifdef _M_IX86

FORCEINLINE PVOID _InterlockedCompareExchangePointer(
    __inout PVOID volatile *Destination,
    __in PVOID Exchange,
    __in PVOID Comparand
    )
{
    return (PVOID)_InterlockedCompareExchange(
        (PLONG_PTR)Destination,
        (LONG_PTR)Exchange,
        (LONG_PTR)Comparand
        );
}

FORCEINLINE PVOID _InterlockedExchangePointer(
    __inout PVOID volatile *Destination,
    __in PVOID Exchange
    )
{
    return (PVOID)_InterlockedExchange(
        (PLONG_PTR)Destination,
        (LONG_PTR)Exchange
        );
}

#endif

FORCEINLINE VOID PhpEnsureEventCreated(
    __inout PHANDLE Handle
    )
{
    HANDLE handle;

    if (*Handle != NULL)
        return;

    handle = CreateSemaphore(NULL, 0, MAXLONG, NULL);

    if (_InterlockedCompareExchangePointer(
        Handle,
        handle,
        NULL
        ) != NULL)
    {
        CloseHandle(handle);
    }
}

VOID PhAcquireFastLockExclusive(
    __inout PPH_FAST_LOCK FastLock
    )
{
    ULONG value;
    ULONG i = 0;

    while (TRUE)
    {
        value = FastLock-&gt;Value;

        if (!(value &amp; (PH_LOCK_OWNED | PH_LOCK_EXCLUSIVE_WAKING)))
        {
            if (_InterlockedCompareExchange(
                &amp;FastLock-&gt;Value,
                value + PH_LOCK_OWNED,
                value
                ) == value)
                break;
        }
        else if (i &gt;= PhLockSpinCount)
        {
            PhpEnsureEventCreated(&amp;FastLock-&gt;ExclusiveWakeEvent);

            if (_InterlockedCompareExchange(
                &amp;FastLock-&gt;Value,
                value + PH_LOCK_EXCLUSIVE_WAITERS_INC,
                value
                ) == value)
            {
                if (WaitForSingleObject(
                    FastLock-&gt;ExclusiveWakeEvent,
                    INFINITE
                    ) != WAIT_OBJECT_0)
                {
                    // You might want to raise an exception here.
                }

                do
                {
                    value = FastLock-&gt;Value;
                } while (_InterlockedCompareExchange(
                    &amp;FastLock-&gt;Value,
                    value + PH_LOCK_OWNED - PH_LOCK_EXCLUSIVE_WAKING,
                    value
                    ) != value);

                break;
            }
        }

        i++;
        YieldProcessor();
    }
}

VOID PhAcquireFastLockShared(
    __inout PPH_FAST_LOCK FastLock
    )
{
    ULONG value;
    ULONG i = 0;

    while (TRUE)
    {
        value = FastLock-&gt;Value;

        if (!(value &amp; (
            PH_LOCK_OWNED |
            (PH_LOCK_SHARED_OWNERS_MASK &lt;&lt; PH_LOCK_SHARED_OWNERS_SHIFT) |
            PH_LOCK_EXCLUSIVE_MASK
            )))
        {
            if (_InterlockedCompareExchange(
                &amp;FastLock-&gt;Value,
                value + PH_LOCK_OWNED + PH_LOCK_SHARED_OWNERS_INC,
                value
                ) == value)
                break;
        }
        else if (
            (value &amp; PH_LOCK_OWNED) &amp;&amp;
            ((value &gt;&gt; PH_LOCK_SHARED_OWNERS_SHIFT) &amp; PH_LOCK_SHARED_OWNERS_MASK) &gt; 0 &amp;&amp;
            !(value &amp; PH_LOCK_EXCLUSIVE_MASK)
            )
        {
            if (_InterlockedCompareExchange(
                &amp;FastLock-&gt;Value,
                value + PH_LOCK_SHARED_OWNERS_INC,
                value
                ) == value)
                break;
        }
        else if (i &gt;= PhLockSpinCount)
        {
            PhpEnsureEventCreated(&amp;FastLock-&gt;SharedWakeEvent);

            if (_InterlockedCompareExchange(
                &amp;FastLock-&gt;Value,
                value + PH_LOCK_SHARED_WAITERS_INC,
                value
                ) == value)
            {
                if (WaitForSingleObject(
                    FastLock-&gt;SharedWakeEvent,
                    INFINITE
                    ) != WAIT_OBJECT_0)
                {
                    // You might want to raise an exception here.
                }

                continue;
            }
        }

        i++;
        YieldProcessor();
    }
}

VOID PhReleaseFastLockExclusive(
    __inout PPH_FAST_LOCK FastLock
    )
{
    ULONG value;

    while (TRUE)
    {
        value = FastLock-&gt;Value;

        if ((value &gt;&gt; PH_LOCK_EXCLUSIVE_WAITERS_SHIFT) &amp; PH_LOCK_EXCLUSIVE_WAITERS_MASK)
        {
            if (_InterlockedCompareExchange(
                &amp;FastLock-&gt;Value,
                value - PH_LOCK_OWNED + PH_LOCK_EXCLUSIVE_WAKING - PH_LOCK_EXCLUSIVE_WAITERS_INC,
                value
                ) == value)
            {
                ReleaseSemaphore(FastLock-&gt;ExclusiveWakeEvent, 1, NULL);

                break;
            }
        }
        else
        {
            ULONG sharedWaiters;

            sharedWaiters = (value &gt;&gt; PH_LOCK_SHARED_WAITERS_SHIFT) &amp; PH_LOCK_SHARED_WAITERS_MASK;

            if (_InterlockedCompareExchange(
                &amp;FastLock-&gt;Value,
                value &amp; ~(PH_LOCK_OWNED | (PH_LOCK_SHARED_WAITERS_MASK &lt;&lt; PH_LOCK_SHARED_WAITERS_SHIFT)),
                value
                ) == value)
            {
                if (sharedWaiters)
                    ReleaseSemaphore(FastLock-&gt;SharedWakeEvent, sharedWaiters, 0);

                break;
            }
        }

        YieldProcessor();
    }
}

VOID PhReleaseFastLockShared(
    __inout PPH_FAST_LOCK FastLock
    )
{
    ULONG value;

    while (TRUE)
    {
        value = FastLock-&gt;Value;

        if (((value &gt;&gt; PH_LOCK_SHARED_OWNERS_SHIFT) &amp; PH_LOCK_SHARED_OWNERS_MASK) &gt; 1)
        {
            if (_InterlockedCompareExchange(
                &amp;FastLock-&gt;Value,
                value - PH_LOCK_SHARED_OWNERS_INC,
                value
                ) == value)
                break;
        }
        else if ((value &gt;&gt; PH_LOCK_EXCLUSIVE_WAITERS_SHIFT) &amp; PH_LOCK_EXCLUSIVE_WAITERS_MASK)
        {
            if (_InterlockedCompareExchange(
                &amp;FastLock-&gt;Value,
                value - PH_LOCK_OWNED + PH_LOCK_EXCLUSIVE_WAKING -
                PH_LOCK_SHARED_OWNERS_INC - PH_LOCK_EXCLUSIVE_WAITERS_INC,
                value
                ) == value)
            {
                ReleaseSemaphore(FastLock-&gt;ExclusiveWakeEvent, 1, NULL);

                break;
            }
        }
        else
        {
            if (_InterlockedCompareExchange(
                &amp;FastLock-&gt;Value,
                value - PH_LOCK_OWNED - PH_LOCK_SHARED_OWNERS_INC,
                value
                ) == value)
                break;
        }

        YieldProcessor();
    }
}

BOOLEAN PhTryAcquireFastLockExclusive(
    __inout PPH_FAST_LOCK FastLock
    )
{
    ULONG value;

    value = FastLock-&gt;Value;

    if (value &amp; (PH_LOCK_OWNED | PH_LOCK_EXCLUSIVE_WAKING))
        return FALSE;

    return _InterlockedCompareExchange(
        &amp;FastLock-&gt;Value,
        value + PH_LOCK_OWNED,
        value
        ) == value;
}

BOOLEAN PhTryAcquireFastLockShared(
    __inout PPH_FAST_LOCK FastLock
    )
{
    ULONG value;

    value = FastLock-&gt;Value;

    if (value &amp; PH_LOCK_EXCLUSIVE_MASK)
        return FALSE;

    if (!(value &amp; PH_LOCK_OWNED))
    {
        return _InterlockedCompareExchange(
            &amp;FastLock-&gt;Value,
            value + PH_LOCK_OWNED + PH_LOCK_SHARED_OWNERS_INC,
            value
            ) == value;
    }
    else if ((value &gt;&gt; PH_LOCK_SHARED_OWNERS_SHIFT) &amp; PH_LOCK_SHARED_OWNERS_MASK)
    {
        return _InterlockedCompareExchange(
            &amp;FastLock-&gt;Value,
            value + PH_LOCK_SHARED_OWNERS_INC,
            value
            ) == value;
    }
    else
    {
        return FALSE;
    }
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wj32.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wj32.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wj32.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wj32.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wj32.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wj32.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wj32.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wj32.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wj32.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wj32.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wj32.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wj32.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wj32.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wj32.wordpress.com/261/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wj32.wordpress.com&amp;blog=1795509&amp;post=261&amp;subd=wj32&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wj32.wordpress.com/2010/01/23/fast-reader-writer-lock-in-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dab4ece81a9b8832323ef2f73fcf12e?s=96&#38;d=identicon" medium="image">
			<media:title type="html">wj32</media:title>
		</media:content>
	</item>
	</channel>
</rss>
