<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Concurrency, Part 9 - APIs that enable scalable programming</title><link>http://blogs.msdn.com/larryosterman/archive/2005/03/02/383685.aspx</link><description>Sorry, I just noticed that this didn't get posted yesterday - I don't know what happened, but... As I mentioned the other day , Win32 provides a number of tools for writing scalable applications. Today I want to catalog some of them. Remember, that the</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Concurrency, Part 9 - APIs that enable scalable programming</title><link>http://blogs.msdn.com/larryosterman/archive/2005/03/02/383685.aspx#384015</link><pubDate>Thu, 03 Mar 2005 01:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:384015</guid><dc:creator>Norman Diamond</dc:creator><description>&amp;gt; InitializeCriticalSectionAndSpinCount API&lt;br&gt;&lt;br&gt;For multiprocessor systems the advantage is obvious, as long as the thread trying to enter the critical section is on a different processor from the thread that already owns the critical section.  The current owner might really leave quickly.&lt;br&gt;&lt;br&gt;But for uniprocessor systems it still looks like a disadvantage.  The caller still has to go to sleep and the kernel still has to switch the context back to the current owner at some time in order for the current owner to ever have a chance of exiting the critical section.  So why waste CPU time spinning instead of letting some other executable thread do something?  Sure you've reduced lock convoys but you've done it by turning the same CPU cycles into pure waste.&lt;br&gt;&lt;br&gt;You say that this API was implemented in Windows 98.  There were no multiprocessor Windows 98 implementations, right?  How could this ever be anything other than a loss on Windows 98?&lt;br&gt;&lt;br&gt;If you want the caller of EnterCriticalSection to get the rest of the quantum that it was going to have, then the theoretical answer is to give that thread a minor priority boost and the rest of the quantum that it was using.  But from everything I've read about Windows, priorities still aren't fine-grained enough to do this without impinging on the genuinely higher priorities of higher priority tasks.  Anyway, the theoretical answer isn't to spin when you've only got one CPU.&lt;br&gt;&lt;br&gt;&amp;gt; Sorry, I just noticed that this didn't get&lt;br&gt;&amp;gt; posted yesterday - I don't know what&lt;br&gt;&amp;gt; happened, but...&lt;br&gt;&lt;br&gt;The race between the process that submits threads for posting and the thread that actually posts them went the other way ^_^</description></item><item><title>re: Concurrency, Part 9 - APIs that enable scalable programming</title><link>http://blogs.msdn.com/larryosterman/archive/2005/03/02/383685.aspx#384034</link><pubDate>Thu, 03 Mar 2005 01:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:384034</guid><dc:creator>Larry Osterman</dc:creator><description>Good points Norman.&lt;br&gt;&lt;br&gt;I suspect that on Win98, the &amp;quot;and spin count&amp;quot; part of the API was a NOP (but I don't know, having never written code for Win98).  My suspicion is that they just added a wrapper for the API.&lt;br&gt;&lt;br&gt;For UP machines ICSASC is almost always a loss (I can't think of a situation where it's a win).  But the vast majority of machines are MP machines these days, so it's more important.  Also, the big reason you use this API is if you're trying to remove lock convoys in your application.  If you're seeing lock convoys in your application then it's likely to be a server type application.  And...&lt;br&gt;</description></item><item><title>re: Concurrency, Part 9 - APIs that enable scalable programming</title><link>http://blogs.msdn.com/larryosterman/archive/2005/03/02/383685.aspx#384104</link><pubDate>Thu, 03 Mar 2005 05:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:384104</guid><dc:creator>Norman Diamond</dc:creator><description>&amp;gt; But the vast majority of machines are MP&lt;br&gt;&amp;gt; machines these days&lt;br&gt;&lt;br&gt;Now the principal asks why you misspelled &amp;quot;servers&amp;quot;  ^_^</description></item><item><title>re: Concurrency, Part 9 - APIs that enable scalable programming</title><link>http://blogs.msdn.com/larryosterman/archive/2005/03/02/383685.aspx#384151</link><pubDate>Thu, 03 Mar 2005 09:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:384151</guid><dc:creator>Dave Sellars</dc:creator><description>MSDN says that InterlockedIncrement() returns the RESULTING value, not what you said (the previous value). This is an important difference. BTW, excellent column, Larry, I just discovered it and am enjoying it immensely.</description></item><item><title>re: Concurrency, Part 9 - APIs that enable scalable programming</title><link>http://blogs.msdn.com/larryosterman/archive/2005/03/02/383685.aspx#384314</link><pubDate>Thu, 03 Mar 2005 16:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:384314</guid><dc:creator>Giampiero De Ciantis</dc:creator><description>This is more of a .NET question, but what is the difference between concurrency with threads and asynchronous events? Is it the same under the hood or does the CLR do something funky? &lt;br&gt;&lt;br&gt;Would the basics that you mention work for message passing languages like Erlang?&lt;br&gt;&lt;br&gt;How does Micro C++ fit change the equation?&lt;br&gt;&lt;br&gt;I now you already mentioned that you aren't the expert in concurrency. Just fielding the questions to see if you may now any of the answers.</description></item><item><title>re: Concurrency, Part 9 - APIs that enable scalable programming</title><link>http://blogs.msdn.com/larryosterman/archive/2005/03/02/383685.aspx#384422</link><pubDate>Thu, 03 Mar 2005 18:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:384422</guid><dc:creator>Matt Stupple</dc:creator><description>What about the memory barriers imposed by use of the InterlockedFoo() operations? My (very superficial) understanding is that they shouldn't be viewed as a panacea for 'lock free' programming because of the potential costs of the memory barriers...?</description></item><item><title>re: Concurrency, Part 9 - APIs that enable scalable programming</title><link>http://blogs.msdn.com/larryosterman/archive/2005/03/02/383685.aspx#384427</link><pubDate>Thu, 03 Mar 2005 18:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:384427</guid><dc:creator>Larry Osterman</dc:creator><description>Matt, you're right, there are memory barriers, and they do have a cost associated with them.  But their cost is effectively 0 when compared to the cost of a context switch.&lt;br&gt;&lt;br&gt;Giampiero, I don't think I can answer that, I don't know how the CLR handles asynchronous events.  </description></item></channel></rss>