<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/wordpress-mu-1.2.3-2.2.1" -->
<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/"
	>

<channel>
	<title>The Oracle at Delphi</title>
	<link>http://blogs.codegear.com/abauer</link>
	<description>Various items, tidbits, and ramblings related to Delphi. Hosted by Allen Bauer, Embarcadero Chief Scientist.</description>
	<pubDate>Wed, 16 Jul 2008 17:49:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=wordpress-mu-1.2.3-2.2.1</generator>
	<language>en-US</language>
			<item>
		<title>Tibur&#243;n - String Theory</title>
		<link>http://blogs.codegear.com/abauer/2008/07/16/38864</link>
		<comments>http://blogs.codegear.com/abauer/2008/07/16/38864#comments</comments>
		<pubDate>Wed, 16 Jul 2008 17:49:19 +0000</pubDate>
		<dc:creator>Allen Bauer</dc:creator>
		
		<category><![CDATA[CodeGear]]></category>

		<guid isPermaLink="false">http://blogs.codegear.com/abauer/2008/07/16/38864</guid>
		<description><![CDATA[No, not that String Theory, or even this one. What this is about is an interesting extension to AnsiString. During the field test cycle of Tiburón and our own internal porting of the IDE code (which was accomplished in about 1.5 months, by 2-3 folks, with &#62; 2 million LOC), it became clear that there [...]]]></description>
			<content:encoded><![CDATA[<p>No, not that <a href="http://en.wikipedia.org/wiki/String_theory">String Theory</a>, or even <a href="http://blogs.codegear.com/abauer/2008/01/09/38845">this one</a>. What this is about is an interesting extension to AnsiString. During the field test cycle of Tiburón and our own internal porting of the IDE code (which was accomplished in about 1.5 months, by 2-3 folks, with &gt; 2 million LOC), it became clear that there was a need for easily encoding UTF16 character data as UTF8. For the astute among you, you probably already know about the RTL defined UTF8String which is really just an alias to AnsiString. The problem is that it is UTF8 <em>in name only</em>. Unless you explicitly ensured that only UTF8 data was placed into the payload, it could just as easily hold normal Ansi character data. We needed to make the use of UTF8String easier. As we looked at how AnsiString worked, it was clear that AnsiString always had this "<a href="http://www.google.com/search?q=define%3A+affinity">affinity</a>" to carry it&#8217;s data payload encoded as whatever the RTL had determined was the active code page, <em>at runtime</em>. So we wondered, "what if we could create an AnsiString type where the programmer determined at <em>compile time, </em>the code page affinity for AnsiString?"</p>
<p>It turns out that, to Windows, UTF8 encoding is just another code page. Down in the RTL, the conversions to/from UnicodeString or WideString use the Windows API functions <a href="http://msdn.microsoft.com/en-us/library/ms776420(VS.85).aspx">WideCharToMultiByte</a>() and <a href="http://msdn.microsoft.com/en-us/library/ms776413(VS.85).aspx">MultiByteToWideChar</a>(). One of the parameters is the code page identifier to or from which the data is converted. If you pass CP_UTF8 (65001) to those functions, they&#8217;ll convert between UTF16 and UTF8. This is a <em>lossless</em> conversion. In Tiburón, we&#8217;re introducing an enhancement to declaring your own "typed" AnsiString. You have always been able to create a unique type based on any intrinsic type by declaring the new type with the "typed type" syntax:</p>
<p>
<pre><code><strong>type</strong>
  MyString = <strong>type</strong> AnsiString;
</code>
</pre>
<p>This would create a new type that is <em>assignment compatible*</em> with AnsiString, but with a unique type name and a unique RTTI structure. We&#8217;ve used this in VCL to distinguish normal "strings" from special strings such as TFileName or TCaption. By creating these unique string types, it was possible to create property editors that would be associated with a specific type of property, regardless of which component it used on or what the property name was. This is how only the Caption property on many components will automatically update the live design-time component as you type in the Caption value.</p>
<p>The thing is, with the above declaration, MyString will continue to always have an affinity for whatever the current runtime code page was. So, we introduced the following syntax <em>for AnsiString only:</em></p>
<p>
<pre><code><strong>type</strong>
  MyString = <strong>type</strong> AnsiString(&lt;1..65534&gt;);
</code>
</pre>
<p>You can now control the code page affinity of any "typed type" AnsiString at compile time. The "parameter" to AnsiString must be a word constant expression. The values 0 and 65535 have special meanings. 0 is a normal AnsiString, and 65535 ($FFFF) means "no affinity." $FFFF is worth noting here as already being declared as a RawByteString. When assigning between AnsiStrings or passing them as parameters, if the code page affinity of the source and destination strings are different, an automatic conversion is done. In order to minimize potential dataloss during the conversion, all conversions go "through" UTF16. However, a string with an affinity of $FFFF tells both the compiler and the RTL, that none of these conversions should be done and to just move over the payload. In practice, however, there would be only a few instances of needing to use RawByteString, but it is there for your use.</p>
<p>So we now have the following declarations in the System unit:</p>
<p>
<pre><code><strong>type</strong>
  UTF8String = <strong>type</strong> AnsiString(CP_UTF8);
  RawByteString = <strong>type</strong> AnsiString($FFFF);
</code>
</pre>
<p>Like I stated previously, any assignment (or passing as a parameter to procedure or function) where the code page affinity between the source and destination are different, the payload will automatically be converted. Say you have a function that must only take UTF8 data. You can declare it like this:</p>
<p>
<pre><code><strong>procedure</strong> WriteUTF8Data(const Data: UTF8String);
<strong>begin</strong>
  // write UTF8 data to stream, file, socket, etc&#8230;
<strong>end</strong>;
</code>
</pre>
<p>Now, no matter what type of string you pass to this procedure, you know that the payload will have been coerced into UTF8. Pass a normal AnsiString, and the data arrives as the UTF8 version of that AnsiString converted from whatever the active codepage was or whatever that AnsiString&#8217;s affinity was set to. Pass a UnicodeString or WideString to the function and it too will be converted to UTF8. Pretty cool, no?</p>
<p>With the title to this post&#8230; All those physicists out there are going to hate me and <a href="http://www.google.com/search?q=String+Theory">Google</a>.. hehe <img src='http://blogs.codegear.com/abauer/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>*"Assignment compatible" means that you can assign or pass as a parameter from one "typed type" to another "typed type" or the intrinsic type on which it was based. They are <em>not</em> "var/out parameter" compatible. This means you can pass them <em>by value</em> to a function but not <em>by reference</em>.</p>
<p class="akst_link"><a href="http://blogs.codegear.com/abauer/?p=38864&amp;akst_action=share-this"  title="Post to del.icio.us, etc." id="akst_link_38864" class="akst_share_link" rel="nofollow">Share This</a> | <a href="mailto:?subject=Tibur%26oacute%3Bn%20-%20String%20Theory&body=Have you seen this? http%3A%2F%2Fblogs.codegear.com%2Fabauer%2F2008%2F07%2F16%2F38864" id="akst_email_38864" class="akst_share_email" rel="nofollow">Email this page to a friend</a></p>]]></content:encoded>
			<wfw:commentRss>http://blogs.codegear.com/abauer/2008/07/16/38864/feed</wfw:commentRss>
		</item>
		<item>
		<title>Brand New Day&#8230;</title>
		<link>http://blogs.codegear.com/abauer/2008/07/01/38863</link>
		<comments>http://blogs.codegear.com/abauer/2008/07/01/38863#comments</comments>
		<pubDate>Tue, 01 Jul 2008 16:21:38 +0000</pubDate>
		<dc:creator>Allen Bauer</dc:creator>
		
		<category><![CDATA[CodeGear]]></category>

		<guid isPermaLink="false">http://blogs.codegear.com/abauer/2008/07/01/38863</guid>
		<description><![CDATA[Well, my access card worked.&#160; I guess I still have a job :-). 
I just finished listening to a company (Embarcadero not Borland) wide conference call announcing to the whole company the closure of the Embarcadero+CodeGear deal. Wayne Williams, our new boss, made some very encouraging statements. Most notably was that just like ER/Studio, RapidSQL, [...]]]></description>
			<content:encoded><![CDATA[<p>Well, my access card worked.&nbsp; I guess I still have a job :-). </p>
<p>I just finished listening to a company (Embarcadero not Borland) wide conference call announcing to the whole company the closure of the Embarcadero+CodeGear deal. Wayne Williams, our new boss, made some very encouraging statements. Most notably was that just like <a href="http://www.embarcadero.com/products/erstudio/">ER/Studio</a>, <a href="http://www.embarcadero.com/products/rapidsql/">RapidSQL</a>, and <a href="http://www.embarcadero.com/products/dbartisan/">DBArtisan</a>, <a href="http://www.codegear.com/products/radstudio">Delphi/C++Builder</a> are core Embarcadero product offerings. This means that these products are key to the business. Yes, there are many other products being sold, incubated and introduced, but it is the aforementioned products that form the pillars on which the company is based. Without them, many of the other products would not be possible. Like the foundation of a home, you just don&#8217;t take a metaphoric jackhammer to them and expect the structure (the company) to remain sound.</p>
<p>Another encouraging (or maybe scary, depending upon your perspective) point was that we are the last independent tools vendor with the breadth of offerings we have out there. This means no vendor or stack lock-in. We have tools for nearly every database and OS platform out there. We are also one the of the very few software companies that offer very strong non-Open Source tools right along side tools built either on or for Open Source stacks. <a href="http://www.codegear.com/products/jbuilder">JBuilder</a> and <a href="http://www.codegear.com/products/3rdrail">3rdRail</a> are built on top of the very popular Eclipse framework. <a href="http://www.codegear.com/products/delphi/php">Delphi for PHP</a> and <a href="http://www.codegear.com/products/3rdrail/">3rdRail</a> are built for the very popular and widely used Open Source PHP and Ruby/Rails environments, respectively.</p>
<p>How things will change or even stay the same is still being planned and scoped. A lot of work had been done between the announcement of this deal and its close, but now is where most of the work can actually take place. Now that we&#8217;re no longer joined to Borland, we can now chart a new course under a new captain. I wish all the best for Borland as I&#8217;ve seen many happy and exciting days while there.</p>
<p>An interesting anomaly is that many of the CodeGear folks have had their service bridged, which means that some of us have, on paper, now worked for Embarcadero longer then they&#8217;ve existed :-). This is now day 6022 for me.</p>
<p class="akst_link"><a href="http://blogs.codegear.com/abauer/?p=38863&amp;akst_action=share-this"  title="Post to del.icio.us, etc." id="akst_link_38863" class="akst_share_link" rel="nofollow">Share This</a> | <a href="mailto:?subject=Brand%20New%20Day...&body=Have you seen this? http%3A%2F%2Fblogs.codegear.com%2Fabauer%2F2008%2F07%2F01%2F38863" id="akst_email_38863" class="akst_share_email" rel="nofollow">Email this page to a friend</a></p>]]></content:encoded>
			<wfw:commentRss>http://blogs.codegear.com/abauer/2008/07/01/38863/feed</wfw:commentRss>
		</item>
		<item>
		<title>The Last Day.</title>
		<link>http://blogs.codegear.com/abauer/2008/06/30/38862</link>
		<comments>http://blogs.codegear.com/abauer/2008/06/30/38862#comments</comments>
		<pubDate>Mon, 30 Jun 2008 23:00:56 +0000</pubDate>
		<dc:creator>Allen Bauer</dc:creator>
		
		<category><![CDATA[Work]]></category>

		<category><![CDATA[CodeGear]]></category>

		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blogs.codegear.com/abauer/2008/06/30/38862</guid>
		<description><![CDATA[Today is my last official day as a Borland/CodeGear employee. After today, I will have been a Borland/CodeGear employee for 6021 days, or 16 years, 5 months, and 25 days. What is interesting about this is that tomorrow, I will continue to drive to the same building, ride the same elevator, and unlock the same [...]]]></description>
			<content:encoded><![CDATA[<p>Today is my last official day as a Borland/CodeGear employee. After today, I will have been a Borland/CodeGear employee for 6021 days, or 16 years, 5 months, and 25 days. What is interesting about this is that tomorrow, I will continue to drive to the same building, ride the same elevator, and unlock the same office door. The only difference will be that I will be employed by Embarcadero. It has certainly been an interesting ride in my many years at Borland/CodeGear.</p>
<p>For some perspective, I started when the Borland stock was around $80 a share (ouch). The new Borland Campus wasn&#8217;t completed. Borland occupied a reasonably large number of buildings throughout Scotts Valley. If Borland didn&#8217;t occupy some or all of a building, chances are <a href="http://www.seagate.com">Seagate</a> did. To move between the various buildings, there was a continuously running shuttle bus service for Borland employees. I also remember the clout that Borland had locally. When we (my family and myself) first arrived and were looking for someplace to rent, when asked where I worked and I said Borland, suddenly we were at the top of the list without any kind of other checks. It was pretty nice.</p>
<p>After today, there will be no official presence of Borland in Scotts Valley. The only thing linked to Borland will be name on the lease they maintain on part of this building that was once the Borland Corporate HQ and campus. Embarcadero will sub-lease the space we currently occupy from Borland.</p>
<p>Even though there have been many things Borland has done over the years that I firmly disagreed with, they&#8217;ve also done some pretty good stuff too. I&#8217;ve learned so much more than I ever could have imagined about software, the software industry, developer tools, frameworks, and compilers. I&#8217;ve also had the pleasure of knowing and meeting many folks in the industry from all around the world.</p>
<p>Tomorrow will start a new chapter with new challenges and opportunities. I&#8217;m sure it will take some time until the dust settles, the cultures merge, and things settle down to the right groove. Don&#8217;t expect any earth-shattering announcements or radical changes immediately out of the gate. This is a new experience for nearly all involved, so some period of acclimation is bound to take place.</p>
<p class="akst_link"><a href="http://blogs.codegear.com/abauer/?p=38862&amp;akst_action=share-this"  title="Post to del.icio.us, etc." id="akst_link_38862" class="akst_share_link" rel="nofollow">Share This</a> | <a href="mailto:?subject=The%20Last%20Day.&body=Have you seen this? http%3A%2F%2Fblogs.codegear.com%2Fabauer%2F2008%2F06%2F30%2F38862" id="akst_email_38862" class="akst_share_email" rel="nofollow">Email this page to a friend</a></p>]]></content:encoded>
			<wfw:commentRss>http://blogs.codegear.com/abauer/2008/06/30/38862/feed</wfw:commentRss>
		</item>
		<item>
		<title>&#62;10 years in the making&#8230;</title>
		<link>http://blogs.codegear.com/abauer/2008/05/08/38861</link>
		<comments>http://blogs.codegear.com/abauer/2008/05/08/38861#comments</comments>
		<pubDate>Thu, 08 May 2008 19:02:11 +0000</pubDate>
		<dc:creator>Allen Bauer</dc:creator>
		
		<category><![CDATA[CodeGear]]></category>

		<guid isPermaLink="false">http://blogs.codegear.com/abauer/2008/05/08/38861</guid>
		<description><![CDATA[Sure, the latest news of Embarcadero Technologies signing an definitive agreement to acquire the CodeGear portion of Borland&#8217;s business is a recent development. However, looking back on my years here at Borland, I have to chuckle a little bit. I remember sitting with other Delphi team members many years ago on more than one occasion [...]]]></description>
			<content:encoded><![CDATA[<p>Sure, <a href="http://www.codegear.com/about/news/embt">the latest news of Embarcadero Technologies</a> signing an definitive agreement to acquire the <a href="http://www.codegear.com">CodeGear</a> portion of <a href="http://www.borland.com">Borland&#8217;s</a> business is a recent development. However, looking back on my years here at Borland, I have to chuckle a little bit. I remember sitting with other Delphi team members many years ago on more than one occasion waxing poetically about how great it would be to spin out Delphi and the other dev tools products into either a stand-alone company or into the arms of someone who will nurture and cultivate their value. While at the time it was idle chit-chat, who would have thought that this day would actually come?</p>
<p>Throughout the day, yesterday, I got into several IM conversations from former co-workers all asking how I felt about the news. I honestly told them that this is the best outcome for the future of the developer tools products anyone of us here could have imagined. As I was on my way from work last night, I got a phone call on my mobile phone. I was wondering when I would get this call. The voice on the other end said, "Hi Allen, <a href="http://www.removingalldoubt.com">this is Chuck</a>." Yep, I was totally expecting a direct phone call sometime from Chuck. If you&#8217;ve been following any of my posts over the last few years, you know that <a href="http://www.removingalldoubt.com">Chuck Jazdzewski</a> was very instrumental in my getting hired at Borland. Chuck served as my mentor for many years.</p>
<p>Chuck&#8217;s first question was one of concern and wanting to know how I felt about these developments. Thanks, Chuck, that meant a lot. We talked for a while as I was driving. Don&#8217;t worry, I use a bluetooth hands free headset :-). Part of the conversation quickly drifted to our many conversations in the past about how cool it would be to take the dev tools out of Borland. Unfortunately, I arrived at my destination and had to cut the conversation short. I would like to have continued. Chuck agreed that if he had any other questions that he&#8217;d be sure to give me a call.</p>
<p>If there is one thing about my tenure with the Borland developer tools group, it has rarely ever been a dull moment. I doubt that is going to be changing any time soon. Change is something the CodeGear teams have become accustomed to. It&#8217;s great that this change is one of the most positive ones :-).</p>
<p class="akst_link"><a href="http://blogs.codegear.com/abauer/?p=38861&amp;akst_action=share-this"  title="Post to del.icio.us, etc." id="akst_link_38861" class="akst_share_link" rel="nofollow">Share This</a> | <a href="mailto:?subject=%26gt%3B10%20years%20in%20the%20making...&body=Have you seen this? http%3A%2F%2Fblogs.codegear.com%2Fabauer%2F2008%2F05%2F08%2F38861" id="akst_email_38861" class="akst_share_email" rel="nofollow">Email this page to a friend</a></p>]]></content:encoded>
			<wfw:commentRss>http://blogs.codegear.com/abauer/2008/05/08/38861/feed</wfw:commentRss>
		</item>
		<item>
		<title>What a day&#8230;</title>
		<link>http://blogs.codegear.com/abauer/2008/05/07/38860</link>
		<comments>http://blogs.codegear.com/abauer/2008/05/07/38860#comments</comments>
		<pubDate>Thu, 08 May 2008 00:31:44 +0000</pubDate>
		<dc:creator>Allen Bauer</dc:creator>
		
		<category><![CDATA[CodeGear]]></category>

		<guid isPermaLink="false">http://blogs.codegear.com/abauer/2008/05/07/38860</guid>
		<description><![CDATA[Needless to say, it&#8217;s been a crazy day here at CodeGear. I&#8217;m sure the same can be said of the fine folks at Embarcadero. Rather than saying the same things you can read about in all the various outlets and blogs, I figured I&#8217;d give folks my impression of how this is affecting the teams [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codegear.com/about/news/embt">Needless to say, it&#8217;s been a crazy day</a> here at <a href="http://www.codegear.com">CodeGear</a>. I&#8217;m sure the same can be said of the fine folks at <a href="http://ww.embarcadero.com">Embarcadero</a>. Rather than saying the same things you can read about in <a href="http://cdn.codegear.com">all the various outlets</a> and <a href="http://metafrequency.blogspot.com/2008/05/embarcadero-and-codegear.html">blogs</a>, I figured I&#8217;d give folks my impression of how this is affecting the teams here at CodeGear.</p>
<p>At 9am PDT, we held a company "all-hands" meeting here in Scotts Valley, CA. Since this meeting coincided with Borland&#8217;s earnings announcement, this was not an unusual event. Oh sure, the internal rumors had been flying for months. Folks kept saying that "something is happening." After the usual presentation and outline of the deal, there was an opportunity for a Q&amp;A session with <a href="http://blogs.codegear.com/jimdouglas">Jim Douglas</a>, the CodeGear CEO. Jim was candid and frank. Like anything that is a major change, there is bound to be some level of nervousness. In this case, the employees were far more engaged in the meeting that I&#8217;ve seen in the past. It seemed that there was this collective sigh of relief among the whole crowd. We finally made it!</p>
<p><a href="http://blogs.codegear.com/michaelswindell">Michael Swindell</a> presented information about how this is a great fit for both companies and began outlining a lot of the immediate and long term opportunities. When something fits this well, it&#8217;s easy for people to just "get it." It&#8217;s not a tough thing to "sell." If you&#8217;re a CodeGear customer, I would encourage you to head on over to <a href="http://www.embarcadero.com">Embarcadero&#8217;s</a> site and just browse around and look at what they&#8217;re offering. You should also take a moment to read this <a href="http://metafrequency.blogspot.com/2008/05/embarcadero-and-codegear.html">blog post from Greg Keller</a>.</p>
<p>Throughout most of today, intermixed with doing a little bit of coding, I&#8217;ve also been cruising the newsgroups, blogosphere, and other message boards. So far the overall tone is very positive and upbeat. There are lots of questions and concerns. It&#8217;s only the first day, so I&#8217;m sure as folks have a chance to digest what this all means, the real questions will start flowing. Off the top, right now there are no plans to veer from our current roadmaps or to interrupt any current schedules. As a matter of fact, this was the directive given from the Embarcadero folks to make sure we&#8217;re still on track to deliver what we&#8217;ve committed to.</p>
<p>I also spent some time roaming through the halls here in Scotts Valley.&nbsp; After the 9am meeting, there was a lot of hallway conversations about what this all means. There was no "hand-wringing" and "angst" among the team that I could see. In fact, most folks were already talking about what Embarcadero does, the products they offer, and how they fit with what we&#8217;re doing. Those are exactly the conversations we should be having internally. By the afternoon, most of the team had settled back into their routine and the development engine was back running on all cylinders.</p>
<p>So if you have any questions or comments, feel free to let me know and post through the comment system here. As I already stated above, it is business as usual in terms of products, schedules and features. As we approach the final close of this deal, more and more information will become available. So if I cannot answer your question right away, I hope to be able to do so in the coming weeks.</p>
<p><strong>UPDATE:</strong> It seems that many of you are already hitting Embarcadero&#8217;s site.&nbsp; It appears to be suffering from a mild case of "slashdot effect". This is a good thing. Let&#8217;s make sure they know how engaged, passionate, and committed the CodeGear customers are.</p>
<p class="akst_link"><a href="http://blogs.codegear.com/abauer/?p=38860&amp;akst_action=share-this"  title="Post to del.icio.us, etc." id="akst_link_38860" class="akst_share_link" rel="nofollow">Share This</a> | <a href="mailto:?subject=What%20a%20day...&body=Have you seen this? http%3A%2F%2Fblogs.codegear.com%2Fabauer%2F2008%2F05%2F07%2F38860" id="akst_email_38860" class="akst_share_email" rel="nofollow">Email this page to a friend</a></p>]]></content:encoded>
			<wfw:commentRss>http://blogs.codegear.com/abauer/2008/05/07/38860/feed</wfw:commentRss>
		</item>
		<item>
		<title>Fly! Be free! (this time for sure!).</title>
		<link>http://blogs.codegear.com/abauer/2008/05/07/38859</link>
		<comments>http://blogs.codegear.com/abauer/2008/05/07/38859#comments</comments>
		<pubDate>Wed, 07 May 2008 15:34:23 +0000</pubDate>
		<dc:creator>Allen Bauer</dc:creator>
		
		<category><![CDATA[CodeGear]]></category>

		<guid isPermaLink="false">http://blogs.codegear.com/abauer/2008/05/07/38859</guid>
		<description><![CDATA[Just in case you&#8217;ve not heard the "Good News", you should read it here&#8230; go ahead, I&#8217;ll wait.
&#160;
Well? Is that not some interesting news? If you&#8217;ve been wondering why this blog has been somewhat quiet lately, it&#8217;s been due not only to being "heads-down" on Tiburón, but also because of this news. It&#8217;s been a [...]]]></description>
			<content:encoded><![CDATA[<p>Just in case you&#8217;ve not heard the "Good News", <a href="http://www.codegear.com/article/38124/images/38124/EMBT-CG_Press_Release_050708.pdf">you should read it here</a>&#8230; go ahead, I&#8217;ll wait.</p>
<p>&nbsp;</p>
<p>Well? Is that not some interesting news? If you&#8217;ve been wondering why this blog has been somewhat quiet lately, it&#8217;s been due not only to being "heads-down" on Tiburón, but also because of this news. It&#8217;s been a long-time in coming, that&#8217;s for certain. In the coming days, you&#8217;re sure to hear a lot more about what this means and comments from various sources.&nbsp; Once I&#8217;ve had a chance to gather together some more information, I&#8217;ll be sure to post it here.</p>
<p class="akst_link"><a href="http://blogs.codegear.com/abauer/?p=38859&amp;akst_action=share-this"  title="Post to del.icio.us, etc." id="akst_link_38859" class="akst_share_link" rel="nofollow">Share This</a> | <a href="mailto:?subject=Fly%21%20Be%20free%21%20%28this%20time%20for%20sure%21%29.&body=Have you seen this? http%3A%2F%2Fblogs.codegear.com%2Fabauer%2F2008%2F05%2F07%2F38859" id="akst_email_38859" class="akst_share_email" rel="nofollow">Email this page to a friend</a></p>]]></content:encoded>
			<wfw:commentRss>http://blogs.codegear.com/abauer/2008/05/07/38859/feed</wfw:commentRss>
		</item>
		<item>
		<title>When being &#34;objective&#34; is being &#34;biased&#34;</title>
		<link>http://blogs.codegear.com/abauer/2008/03/18/38858</link>
		<comments>http://blogs.codegear.com/abauer/2008/03/18/38858#comments</comments>
		<pubDate>Wed, 19 Mar 2008 03:41:13 +0000</pubDate>
		<dc:creator>Allen Bauer</dc:creator>
		
		<category><![CDATA[Gadgetry]]></category>

		<category><![CDATA[Family]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://blogs.codegear.com/abauer/2008/03/18/38858</guid>
		<description><![CDATA[I did the most unconscionable thing a few weeks ago. Something I&#8217;ve resisted for a very long time. I bought a Mac. For the first time. Ever. I&#8217;m not against Macs or Apple in general (I own an iPod and a Zune), in fact I find them very quaint and highly capable. Ever since they [...]]]></description>
			<content:encoded><![CDATA[<p>I did the most unconscionable thing a few weeks ago. Something I&#8217;ve resisted for a very long time. I bought a Mac. For the first time. Ever. I&#8217;m not against Macs or Apple in general (I own an iPod and a Zune), in fact I find them very quaint and highly capable. Ever since they succumbed to the Intel juggernaut, my interest was piqued. They are no longer tied to what had become a "boutique" CPU, the PowerPC, but rather to a tried-and-true, mainstream, continuously developed and advancing architecture.&nbsp; Say what you will about all the flaws (and there are many) with whole x86 architecture, it is here to stay, is getting some serious industry investment from both <a href="http://www.intel.com">Intel</a>, <a href="http://www.amd.com">AMD</a>, and even <a href="http://www.via.com.tw/en/products/processors/isaiah-arch/">VIA</a>.&nbsp; Remember the whole IA64 (Itanium) phase?&nbsp; This just proves the point that even Intel cannot stop the force they created.&nbsp; AMD, recognized this early on and created the AMD64 extensions to the existing x86 architecture.&nbsp; Eventually, Intel realized that they&#8217;re only reasonable course of action was to jump onto that bandwagon.&nbsp; It is the biggest example of "if you can&#8217;t beat &#8216;em, join &#8216;em."&nbsp; Apple finally realized this when the powerPC just wasn&#8217;t able to keep up in terms of raw CPU power and the onslaught of the multi-core CPU. Apple had to cut costs, and the easiest way to do it was to join the commoditized-to-the-hilt x86 industry.&nbsp; Yes, this is old news.</p>
<p>I&#8217;ll get to the real motivation for swallowing my pride and buying the Mac in a moment. <a href="http://machinist.salon.com/feature/2008/03/18/true_enough_excerpt_2/">This article</a> popped up on my RSS feed and it really resonated with me.&nbsp; Regardless of the comments, which all too painfully only served to prove the author&#8217;s point (and which I&#8217;m sure there will be comments to this post which will do the same thing), it was interesting to see something I&#8217;ve long suspected, actually put into words.&nbsp; It was also so apropos since I&#8217;ve, sort of, joined the ranks of Mac owners. The gist of this article and the book from which it is excerpted (from what I can gather), is that we&#8217;re all very passionate, like to "belong," and want to feel validated and sometimes even lauded for our choice in car, home, clothes, spouse, occupation, religion, computer, etc&#8230; Yes, I admit that I sometimes feel much the same way as the stereotypical Apple-fanboy when confronted with valid, well-reasoned, <em>unbiased</em> analysis.</p>
<p>This hit home all too well lately because, well, this new Mac is not really mine.&nbsp; Yes, I was involved with its purchase, but I don&#8217;t actually use it.&nbsp; See, my wife has decided to return to school and formally pursue something she&#8217;s come to really enjoy over the past few years, graphic design and layout.&nbsp; It started with doing monthly newsletters for the local Mothers of Twins club (my daughters are twins), then on to doing other various projects, and finally culminated in doing the entire Scotts Valley High School annual Football program.&nbsp; She&#8217;s already committed to do it again for the Fall-2008 season. She has used PCs (natch) for many years and has a very nice 17" notebook. Now that she&#8217;s back in school, which is where she&#8217;s at while I write this post, it became painfully obvious that there is a very clear bias in this particular field toward the mac.&nbsp; Sure, the same applications are available for the PC, but to be truly "accepted" shouldering a mac really helps. Most printers happily work with raw files from these specific applications and will actually charge hefty fee if you submit work using certain PC-only applications. It also makes the professor actually want to talk with you.</p>
<p>Here is where this whole Mac-fanboy, "Apple can do no harm," attitude really hit me.&nbsp; As relayed by my wife, this professor unequivocally stated on the first day of class that you <em>must</em> use the Mac version of the applications.&nbsp; The pure shock and horror on the professor&#8217;s face when asked if one could use the PC versions had to be priceless. A similar attitude was expressed when my wife submitted some homework which had a few things marked off.&nbsp; The professor actually told her that she must not have used a laser printer because a laser printer would have printed correctly.&nbsp; Well, that chapped my hide to no end&#8230; I wanted to load up my nice <em>COLOR </em>laser printer into the truck, drag it up to her class and plop it into the middle of the professor&#8217;s classroom and insist that they prove to me that this is not a stinkin&#8217; laser printer! (no, it is not one of those dye-sublimation or "melted crayon" printers) That lasted for only a few moments as I stood there speechless and dumbfounded.&nbsp; Upon further examination and obtaining more information, it turns out that it wasn&#8217;t printed on the same brand and model laser printer that the professor used.&nbsp; See this is a design and layout class for printed medium, and to grade the work, it is not about the content (which is usually that <a href="http://www.4guysfromrolla.com/demos/latin.asp">funky fake Latin text</a>), but about its layout and presentation on the page.&nbsp; So <em>where</em> things are is more important that whether or not you spelled some word correctly.&nbsp; Ok, that makes sense, she&#8217;ll have to use the school&#8217;s laser printers instead of ours.</p>
<p>The whole purchasing experience was just too surreal.&nbsp; You walk into an Apple store, and it is literally like being a voyeur to this whole cult-like Apple&#8230; thing&#8230;&nbsp; I just cannot explain it.&nbsp; We&#8217;d already researched exactly which Mac we&#8217;re going to get and we&#8217;ll use my wife&#8217;s student ID for a discount.&nbsp; It was simply a matter of walking up to the machine we wanted, point to it and grunt a few syllables about how we&#8217;re going to pay for it and instruct the resident drone to walk back through the stainless steel door at the back of the store to obtain said box of Jobs&#8217; magic.&nbsp; The top-of-the-line 17" MacBook Pro is certainly a sexy bit of hardware. You just cannot deny that. That was nearly four weeks ago. At about two weeks into this, things started going a little south on us.</p>
<p>Once some of the applications needed for the class arrived (after getting some nice deep student discounts), it was time to install them.&nbsp; I get this frantic message from my wife saying that the machine won&#8217;t recognize the disk, and now it won&#8217;t even boot!&nbsp; Hmmm, ok&#8230;&nbsp; not. good.&nbsp; Oh, yeah, the whole "see I knew it!" flags started popping up in my head all over the place.&nbsp; They do have flaws!&nbsp; Eventually, she was able to eject the disk, after making some really horrendous noises and still never recognizing the disk.&nbsp; Less than two weeks old, and the Super-drive is dead.</p>
<p>You gotta love this, you can make an appointment at the "Genius bar" online.&nbsp; So we did.&nbsp; Drove back to the store and met with the "Genius" (yes, I&#8217;m snickering here&#8230;).&nbsp; We explained that we&#8217;ve had the machine for barely two weeks and only now had an occasion to use the drive and this is what happened.&nbsp;&nbsp; They tested it and, sure enough, no workee.&nbsp; Just nasty noises.&nbsp; I was ready for what happened next.&nbsp; I asked if they&#8217;re going to "send it in" for repair.&nbsp; I was all ready to explain that if they went down that road, I&#8217;d be a little irritated because, to me this was a failure that left the factory in that condition and why should we be without the machine for however long it takes to fix it.&nbsp; Also, I&#8217;d just be inclined to return it for a refund.&nbsp; Luckily, they saw the logic agreed to simply replace the machine.</p>
<p>Yeah!&nbsp; They&#8217;re going to replace it&#8230; not so fast, there buckaroo. It turns out that we&#8217;d bought the machine only a few days before Apple decided to announce some minor changes to the whole MacBook line.&nbsp; New things like LED backlit LCD, multi-touch track pad, newer Penryn-based CPU.&nbsp; That all meant they were out of stock.&nbsp; Rats.&nbsp; They said they&#8217;d call once the new machines were in.&nbsp; (I&#8217;ve heard that song and dance all too often) For the next week, we called the store several times and still no shipments. We contemplated simply getting a refund and ordering online, but that would mean not having the machine for school.&nbsp; Finally, yesterday, they actually called. A new machine had been set aside and to come in anytime.&nbsp; After arriving, we explained why we&#8217;re there and they walked back through those sterile stainless steel doors, and returned with a box to which was affixed a post-it note with my wife&#8217;s name on it.&nbsp; Nice.</p>
<p>After about another hour as they transferred the documents, settings and applications, we were on our way.&nbsp; And, yes, I did have them test the drive to make sure it worked :-).&nbsp; All-in-all, Apple&#8217;s service was pleasant and understanding.&nbsp; I&#8217;d have to say that the hardware is no higher or lower quality than a solid ThinkPad or some of the newer Dells (older Dell notebooks had, ahem, some real issues).&nbsp; They&#8217;re certainly more "artsy" looking than a pure utilitarian PC notebook. And OS X? It&#8217;s just different. Some things I like about it, and others just make me want to scream. I can say the same things about XP or Vista.</p>
<p>I&#8217;m sure many will see through my "unbiased" view straight to the obvious bias in this post.&nbsp; And for those Apple-haters, I hope this redeems me; sitting next to me here in my home office, is a new, home-built, overclocked quad-core, 4GB, Vista x64, 512MB nVidia 8800, 1TB raid, PC rig that I had to build to seek forgiveness and cleansing from committing&nbsp; Apple-adultery ;-).</p>
<p class="akst_link"><a href="http://blogs.codegear.com/abauer/?p=38858&amp;akst_action=share-this"  title="Post to del.icio.us, etc." id="akst_link_38858" class="akst_share_link" rel="nofollow">Share This</a> | <a href="mailto:?subject=When%20being%20%26quot%3Bobjective%26quot%3B%20is%20being%20%26quot%3Bbiased%26quot%3B&body=Have you seen this? http%3A%2F%2Fblogs.codegear.com%2Fabauer%2F2008%2F03%2F18%2F38858" id="akst_email_38858" class="akst_share_email" rel="nofollow">Email this page to a friend</a></p>]]></content:encoded>
			<wfw:commentRss>http://blogs.codegear.com/abauer/2008/03/18/38858/feed</wfw:commentRss>
		</item>
		<item>
		<title>Thread pools &#60;&#62; Task handling.</title>
		<link>http://blogs.codegear.com/abauer/2008/02/22/38857</link>
		<comments>http://blogs.codegear.com/abauer/2008/02/22/38857#comments</comments>
		<pubDate>Fri, 22 Feb 2008 23:42:09 +0000</pubDate>
		<dc:creator>Allen Bauer</dc:creator>
		
		<category><![CDATA[Parallel Programming]]></category>

		<category><![CDATA[CodeGear]]></category>

		<category><![CDATA[Delphi]]></category>

		<guid isPermaLink="false">http://blogs.codegear.com/abauer/2008/02/22/38857</guid>
		<description><![CDATA[The Delphi Parallel Library (DPL) tends to occupy a lot of my otherwise idle "thought" time. DPL has been redesigned in my head more times than I can count.&#160; The good news is that it is conceptually beginning to actually take some shape and is finding a direction.&#160; As I&#8217;ve stated before, a lot of [...]]]></description>
			<content:encoded><![CDATA[<p>The Delphi Parallel Library (DPL) tends to occupy a lot of my otherwise idle "thought" time. DPL has been redesigned in my head more times than I can count.&nbsp; The good news is that it is conceptually beginning to actually take some shape and is finding a direction.&nbsp; As I&#8217;ve stated before, a lot of the concepts behind the DPL are taken from <a href="http://threadingbuildingblocks.org/">Intel&#8217;s TBB</a> and <a href="http://msdn.microsoft.com/msdnmag/issues/07/10/Futures/default.aspx">Microsoft&#8217;s TPL</a>.</p>
<p>When I started down this road, it all began as an investigation into various ways of implementing a thread pool.&nbsp; It turns out that this simplistic mechanism really doesn&#8217;t truly address parallelism and concurrent processing.&nbsp; It is merely a way of shoveling off a task into another thread, which may or may not execute concurrently.&nbsp; A thread pool doesn&#8217;t do anything to "load-balance" the work in a constructive manner, nor does it purport to.&nbsp; That is left as an exercise for the user.</p>
<p>While reading and researching all the various approaches to handling parallelism, a few light bulbs started coming on.&nbsp; I&#8217;ve been approaching this whole thing from the wrong angle.&nbsp; I&#8217;d been trying to shoehorn task handling (a task being the smallest unit of work that can be made parallel) concepts into the more general notion of a thread pool.&nbsp; I admit that sometimes I&#8217;m not the sharpest knife in the drawer, but I can recognize when one approach is superior to another.</p>
<p>Rather than starting with the concept of thread pools, a parallel library should really begin at the most basic level, the task or just a unit of work.&nbsp; A task is merely some chunk of code that may or may not execute concurrently.&nbsp; Another thing to remember is that a parallel library is about getting these tasks done as fast as absolutely possible.&nbsp; It is also about keeping as many of the CPU cores as busy as possible with as little idle time and overhead.&nbsp; It <em>is not</em> about fairness. It <em>is</em> about speed.</p>
<p>To best do this, the internal scheduling and management of tasks should control how they are scheduled and processed on the CPU cores.&nbsp; Remember, we&#8217;re talking about the actual real, hardware CPU core (or virtual core, like Hyperthreading).&nbsp; Not a thread.&nbsp; A thread is merely a way to easily segregate tasks among the cores.&nbsp; We&#8217;ll rely on the operating system to make sure that of the available cores, then there are equally as many "threads" actually burning CPU cycles for real work.&nbsp; Any other threads are stuck waiting for their chance at a core.&nbsp; Because of this, a task manager should endeavor to keep the number of running threads as close to equal to the number of available cores.&nbsp; It should also equally handle 1 or 100 cores by making sure as many cores are a busy as possible.</p>
<p>Using a task based approach also requires that the threading and scheduling is completely (or nearly completely) hidden.&nbsp; The user should never think of threads.&nbsp; The user only deals with Tasks and the extra abstractions built on top of them.&nbsp; So it looks like DPL is headed for another rewrite, which is good because each time I do this it is only getting better. I&#8217;ve not spent a whole lot of time on the current iteration as it stands, so this isn&#8217;t much of a setback.&nbsp; </p>
<p>Microsoft&#8217;s TPL is one of the few things to come out in recent years that looks great and performs well.&nbsp; The concepts behind it are very well suited for Delphi.&nbsp; To get an idea of some of the things you can do with it (and eventually the DPL <img src='http://blogs.codegear.com/abauer/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> you really <a href="http://channel9.msdn.com/Showpost.aspx?postid=384229">should watch this video</a>.&nbsp; The really interesting bits come on toward the last 1/2 to 1/3 of the video where they go into the idea behind work stealing and work load balancing.&nbsp; Really, really interesting stuff.&nbsp; <a href="http://www.bluebytesoftware.com/blog/default.aspx">Joe Duffy</a> also addresses how you need to think about parallelism and how it applies to your situation.</p>
<p>As part of this, I just ordered Joe&#8217;s soon to be released book on <a href="http://safari.oreilly.com/9780321434821">Concurrent Programming on Windows Vista</a>.&nbsp; You can actually buy the book online ahead of the actual print release and download a PDF of the work in progress until then.&nbsp; From reading only a few of the online excerpts, it looks to be one of those "must have" tomes for anyone doing any kind of parallel programming in native Windows and in .NET.&nbsp; Even though a lot of the information I know, it is good to have it codified in a consistent organized manner.&nbsp; As I stated in <a href="http://blogs.codegear.com/abauer/2007/09/19/38822">my first post about thread pools,</a> as I dig deeper into this whole subject, I want to make sure that Delphi developers at all levels will find some value in such a library.&nbsp; The best thing you can do at this point is to learn as much about these concepts as you can.&nbsp; Hopefully this blog and others I&#8217;ve been referencing and will reference in the future will be an excellent source of information.&nbsp; I&#8217;m finding that as I write about this, it give me a chance to review my assumptions and design ideas with a critical eye.&nbsp; Hopefully, we can all learn something along the way as well.&nbsp; I know I have so far.</p>
<p class="akst_link"><a href="http://blogs.codegear.com/abauer/?p=38857&amp;akst_action=share-this"  title="Post to del.icio.us, etc." id="akst_link_38857" class="akst_share_link" rel="nofollow">Share This</a> | <a href="mailto:?subject=Thread%20pools%20%26lt%3B%26gt%3B%20Task%20handling.&body=Have you seen this? http%3A%2F%2Fblogs.codegear.com%2Fabauer%2F2008%2F02%2F22%2F38857" id="akst_email_38857" class="akst_share_email" rel="nofollow">Email this page to a friend</a></p>]]></content:encoded>
			<wfw:commentRss>http://blogs.codegear.com/abauer/2008/02/22/38857/feed</wfw:commentRss>
		</item>
		<item>
		<title>Lock my Object&#8230; Please!</title>
		<link>http://blogs.codegear.com/abauer/2008/02/19/38856</link>
		<comments>http://blogs.codegear.com/abauer/2008/02/19/38856#comments</comments>
		<pubDate>Tue, 19 Feb 2008 23:44:48 +0000</pubDate>
		<dc:creator>Allen Bauer</dc:creator>
		
		<category><![CDATA[Parallel Programming]]></category>

		<category><![CDATA[CodeGear]]></category>

		<category><![CDATA[Delphi]]></category>

		<guid isPermaLink="false">http://blogs.codegear.com/abauer/2008/02/19/38856</guid>
		<description><![CDATA[Here&#8217;s a quick recap of all the DPL (Delphi Parallel Library) related posts over the last few months:
A Critical[Section] Difference: Windows XP vs. Windows VistaBreaking the rulesSimmering Unicode, bring DPL to a boil (Part 2)Simmering Unicode, bring DPL to a boilPlacing your code in the forge - Refining a techniqueWhen code lies - A better [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick recap of all the DPL (Delphi Parallel Library) related posts over the last few months:</p>
<p><a href="http://blogs.codegear.com/abauer/2008/02/06/38855">A Critical[Section] Difference: Windows XP vs. Windows Vista</a><br /><a href="http://blogs.codegear.com/abauer/2008/01/22/38851">Breaking the rules</a><br /><a href="http://blogs.codegear.com/abauer/2008/01/18/38850">Simmering Unicode, bring DPL to a boil (Part 2)</a><br /><a href="http://blogs.codegear.com/abauer/2008/01/17/38849">Simmering Unicode, bring DPL to a boil</a><br /><a href="http://blogs.codegear.com/abauer/2007/11/21/38842">Placing your code in the forge - Refining a technique</a><br /><a href="http://blogs.codegear.com/abauer/2007/11/21/38841">When code lies - A better solution</a><br /><a href="http://blogs.codegear.com/abauer/2007/11/12/38839">Stupid Enumerator Tricks - And now for something completely different</a><br /><a href="http://blogs.codegear.com/abauer/2007/11/07/38838">Magical Assembler Incantations - Nested functions and anonymous methods</a><br /><a href="http://blogs.codegear.com/abauer/2007/11/02/38836">The Life and Times of a Thread Pool</a><br /><a href="http://blogs.codegear.com/abauer/2007/10/31/38833">I cut and I cut and it was still too short!</a><br /><a href="http://blogs.codegear.com/abauer/2007/10/05/38830">Spot the deadlock</a><br /><a href="http://blogs.codegear.com/abauer/2007/09/19/38822">Wading in the shallow end of the pool - Thread Pools</a></p>
<p>As another follow on to my discussion of the TMonitor (see the above "Bring DPL to a boil" articles) things have changed a little. The TMonitor class is no longer a separate class that you can create and use. It is now tied directly to any TObject instance or derivative (which means <em>any</em> instance of a Delphi <strong>class</strong>).&nbsp; There is still the notion of a TMonitor but only to serve as a way to tie together the "monitor" functionality. Rather than creating one and setting about to locking/unlocking it, you now only need an object instance. For Tiburón, you merely need to call System.TMonitor.Enter(&lt;obj&gt;); or System.TMonitor.Exit(&lt;obj&gt;); among the other related methods.</p>
<p>I&#8217;ve contemplated putting these methods directly on TObject itself, but there is the issue with calling these methods when a descendant class has a method of the same name. The code will compile and function normally due to Delphi&#8217;s scoping rules, but it could make it harder for users to call those methods in these cases. Thread synchronization should never be done lightly and should require some forethought and planning. A simple rule of thumb is that <em>you should never call unknown code (or code that you&#8217;re not entirely sure where it goes and what it does) while holding a lock.</em>&nbsp; </p>
<p>This now paves the way to add some interesting intrinsic functionality such as using this as the basis for "synchronized" methods or even synchronized code blocks similar to the C# <strong></strong><a href="http://blogs.codegear.com/abauer/2007/09/19/38822">lock keyword</a>. While you&#8217;ve always been able to create an OS critical section, or use some of the helper classes in SyncObjs.pas, this new mechanism will be available on any object.</p>
<p>I merely design it then write about it&#8230; you get to <a href="http://www.thefreedictionary.com/kvetch">kvetch</a> <img src='http://blogs.codegear.com/abauer/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p class="akst_link"><a href="http://blogs.codegear.com/abauer/?p=38856&amp;akst_action=share-this"  title="Post to del.icio.us, etc." id="akst_link_38856" class="akst_share_link" rel="nofollow">Share This</a> | <a href="mailto:?subject=Lock%20my%20Object...%20Please%21&body=Have you seen this? http%3A%2F%2Fblogs.codegear.com%2Fabauer%2F2008%2F02%2F19%2F38856" id="akst_email_38856" class="akst_share_email" rel="nofollow">Email this page to a friend</a></p>]]></content:encoded>
			<wfw:commentRss>http://blogs.codegear.com/abauer/2008/02/19/38856/feed</wfw:commentRss>
		</item>
		<item>
		<title>A Critical[Section] Difference: Windows XP vs. Windows Vista</title>
		<link>http://blogs.codegear.com/abauer/2008/02/06/38855</link>
		<comments>http://blogs.codegear.com/abauer/2008/02/06/38855#comments</comments>
		<pubDate>Wed, 06 Feb 2008 22:41:59 +0000</pubDate>
		<dc:creator>Allen Bauer</dc:creator>
		
		<category><![CDATA[Parallel Programming]]></category>

		<category><![CDATA[CodeGear]]></category>

		<category><![CDATA[Delphi]]></category>

		<guid isPermaLink="false">http://blogs.codegear.com/abauer/2008/02/06/38855</guid>
		<description><![CDATA[No, this isn&#8217;t one of those comparisons!&#160; This is just something somewhat interesting about the difference in the implementation of a critical section in Windows XP vs. Windows Vista.&#160; It seems that Windows Vista is much more resilient in how it handle&#8217;s the misuse of a critical section.&#160; One such degenerate, blatantly obvious case of [...]]]></description>
			<content:encoded><![CDATA[<p>No, this isn&#8217;t one of <em>those</em> comparisons!&nbsp; This is just something somewhat interesting about the difference in the implementation of a critical section in Windows XP vs. Windows Vista.&nbsp; It seems that Windows Vista is much more resilient in how it handle&#8217;s the misuse of a critical section.&nbsp; One such degenerate, blatantly obvious case of misuse is doing the following:</p>
<blockquote><pre>LeaveCriticalSection(CSec);
EnterCriticalSection(CSec);</pre>
</blockquote>
<p>Yes this is wrong on so many levels, but the interesting thing to note is that under Windows XP, the above code hangs at the EnterCriticalSection call because the LeaveCriticalSection call did some very bad damage to the critical section structure.&nbsp; The problem is that the RecursionCount field of the critical section is decremented and left as non-zero (-1) which causes the LockCount field to also be decremented in order to keep the two field counts in sync.&nbsp; When the EnterCriticalSection call is made, the LockCount field is incremented, but it is still non-zero which makes it think there is another owner.&nbsp; The OwningThread Field is compared with the calling thread&#8217;s ID which being 0, is not equal to the calling thread.&nbsp; But no other thread owns the lock!&nbsp; It blithely forges ahead and allocates the wait event and proceeds to block.&nbsp; Oops!</p>
<p>Windows Vista, in contrast, has changed how it manages the LockCount field.&nbsp; Rather than only accumulating the waiters (and recursions) in terms of simply incrementing (or decremented) the LockCount field, it uses the low-bit as the actual indication of holding the lock and accumulates the waiter and recursion counts in the remaining bits.&nbsp; This means that the critical section can now only have 2^31 <strike>recursions and</strike> waiters. (<strong>UPDATE:</strong> Upon further examination, only the waiters are indicated in the LockCount field)&nbsp; Still plenty of space.&nbsp; The upshot of this is that the above degenerate case no longer will cause a complete hang in many cases where it would have.&nbsp; Why they made the change is anybody&#8217;s guess;&nbsp; Maybe <a href="http://blogs.msdn.com/oldnewthing/default.aspx">Raymond Chen</a> can pipe in and explain the reasons&#8230;&nbsp; Seems to me that anyone with doing the above deserves to be put into the <a href="http://en.wikipedia.org/wiki/Penalty_box">penalty box</a>.&nbsp; Now all that is going to happen is that when a program that once used to hang, will now appear to work only to probably show up some other flaw downstream.&nbsp; Seems like a hang/crash now or hang/crash later kind of thing.&nbsp; The end result is still the same.</p>
<p class="akst_link"><a href="http://blogs.codegear.com/abauer/?p=38855&amp;akst_action=share-this"  title="Post to del.icio.us, etc." id="akst_link_38855" class="akst_share_link" rel="nofollow">Share This</a> | <a href="mailto:?subject=A%20Critical%5BSection%5D%20Difference%3A%20Windows%20XP%20vs.%20Windows%20Vista&body=Have you seen this? http%3A%2F%2Fblogs.codegear.com%2Fabauer%2F2008%2F02%2F06%2F38855" id="akst_email_38855" class="akst_share_email" rel="nofollow">Email this page to a friend</a></p>]]></content:encoded>
			<wfw:commentRss>http://blogs.codegear.com/abauer/2008/02/06/38855/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
