<?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>Another reason not to do anything scary in your DllMain: Inadvertent deadlock</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx</link><description>Your DllMain function runs inside the loader lock,
one of the few times the OS lets you run code while one
of its internal locks is held.
This means that you must be extra careful not to violate
a lock hierarchy in your DllMain; otherwise, you
are asking</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Another reason not to do anything scary in your DllMain: Inadvertent deadlock</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#63899</link><pubDate>Wed, 28 Jan 2004 15:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:63899</guid><dc:creator>BTannenbaum</dc:creator><description>We've been bitten by this *many* times before.&lt;br&gt;&lt;br&gt;The problem with the loader lock is that there's no documentation on which functions require it, so it jumps out and bites you when you're making an apparently innocent call.  And to the best of my knowledge, there's no way for me to grab the loader lock in my code, so I could add it to my hierarchy.&lt;br&gt;&lt;br&gt;And of course, this is all timing dependent, so it will work perfectly in the lab and hang randomly at a customer site.</description></item><item><title>re: Another reason not to do anything scary in your DllMain: Inadvertent deadlock</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#64107</link><pubDate>Wed, 28 Jan 2004 22:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64107</guid><dc:creator>BTannenbaum</dc:creator><description>We've been bitten by this *many* times before.&lt;br&gt;&lt;br&gt;The problem with the loader lock is that there's no documentation on which functions require it, so it jumps out and bites you when you're making an apparently innocent call.  And to the best of my knowledge, there's no way for me to grab the loader lock in my code, so I could add it to my hierarchy.&lt;br&gt;&lt;br&gt;And of course, this is all timing dependent, so it will work perfectly in the lab and hang randomly at a customer site.</description></item><item><title>re: Another reason not to do anything scary in your DllMain: Inadvertent deadlock</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#64115</link><pubDate>Wed, 28 Jan 2004 23:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64115</guid><dc:creator>keithmo</dc:creator><description>I hate it when my threads get all &amp;quot;pre-empty&amp;quot;... :-)</description></item><item><title>re: Another reason not to do anything scary in your DllMain: Inadvertent deadlock</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#64151</link><pubDate>Thu, 29 Jan 2004 01:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64151</guid><dc:creator>Norman Diamond</dc:creator><description>To B. Tannenbaum:  Since there's no way to know when you need the loader lock, the following is useless advice, but theoretically it would solve your deadlocks.&lt;br&gt;&lt;br&gt;Define one more lock in your own design which serves no purpose by itself except to waste resources.&lt;br&gt;&lt;br&gt;When you know that the loader lock is going to be grabbed by something you're going to call, lock your lock as just described.  When you know that the thing you called is already finished with the loader lock, release your lock as just described.&lt;br&gt;&lt;br&gt;Include your extra lock in your hierarchy.</description></item><item><title>Static object destructors?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#64416</link><pubDate>Thu, 29 Jan 2004 15:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64416</guid><dc:creator>Sven G. Ali</dc:creator><description>Don't static objects get destructed in DllMain? I think I ran into the loader lock when I had a static object whose job it was to manage a background thread. Its destructor set an event to break the thread out of its loop, then waited on the thread handle. A deadlock happened, and I think the reason was &amp;quot;resource inversion&amp;quot; between the loader lock and the thread handle. My quick &amp;quot;solution&amp;quot; was to bypass DLL_THREAD_DETACH by having the thread terminate itself instead of exiting cleanly. Could this be a valid use of TerminateThread?</description></item><item><title>re: Another reason not to do anything scary in your DllMain: Inadvertent deadlock</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#64440</link><pubDate>Thu, 29 Jan 2004 16:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64440</guid><dc:creator>Mike Dimmick</dc:creator><description>Yes, static objects are destroyed in _DllMainCRTStartup, and yes, this can cause problems. I've been bitten by this, too.&lt;br&gt;&lt;br&gt;Our solution was to remove any setup/teardown code from DllMain and provide InitLibrary/TermLibrary functions separately.&lt;br&gt;&lt;br&gt;It can be quite frustrating to try to debug a process beyond the end of main().</description></item><item><title>re: Another reason not to do anything scary in your DllMain: Inadvertent deadlock</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#64774</link><pubDate>Fri, 30 Jan 2004 02:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64774</guid><dc:creator>Raymond Chen</dc:creator><description>This ties into the comment from Norman Diamond on the other DllMain thread. &lt;br&gt;&lt;br&gt;DllMain is a placeholder name for the actual DLL entry point you choose to use for your DLL.  If you choose to use the C runtimes, then the entry point is really _DllMainCRTStartup.  That function does some other stuff (like managing global destructors/constructors) and then calls a function called (confusingly coincidentally) DllMain.&lt;br&gt;&lt;br&gt;In this case, then, the function you write called &amp;quot;DllMain&amp;quot; is NOT the actual DLL entry point, but an incredible simulation.</description></item><item><title>re: C   scoped static initialization is not thread-safe, on purpose!</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#86663</link><pubDate>Tue, 09 Mar 2004 21:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:86663</guid><dc:creator>The Old New Thing</dc:creator><description /></item><item><title>re: C   scoped static initialization is not thread-safe, on purpose!</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#86676</link><pubDate>Tue, 09 Mar 2004 21:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:86676</guid><dc:creator>The Old New Thing</dc:creator><description /></item><item><title>SimpleScript Part One: DllMain is Boring</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#105341</link><pubDate>Thu, 01 Apr 2004 09:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:105341</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description /></item><item><title>SimpleScript Part One: DllMain is Boring</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#105353</link><pubDate>Thu, 01 Apr 2004 09:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:105353</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description /></item><item><title>Things you shouldn't do, part 1 - DllMain is special</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#118981</link><pubDate>Fri, 23 Apr 2004 19:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:118981</guid><dc:creator>Larry Osterman's WebLog</dc:creator><description /></item><item><title>Things you shouldn't do, part 1 - DllMain is special</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#118984</link><pubDate>Fri, 23 Apr 2004 19:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:118984</guid><dc:creator>Larry Osterman's WebLog</dc:creator><description /></item><item><title>Why does windows hold the loader lock whilst calling DllMain?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#227613</link><pubDate>Fri, 10 Sep 2004 00:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:227613</guid><dc:creator>/* Rambling comments... */</dc:creator><description>I've been &amp;lt;a href=&amp;quot;http://www.larkware.com/Articles/SomeSpelunkingHelp.html&amp;quot;&amp;gt;splunking&amp;lt;/a&amp;gt; around Dll loading recently for a pet project. It's been an interesting journey and this evening I solved the final piece of the puzzle and, when I did, I suddenly wondered, not for the first time, why Windows holds the &amp;lt;a href=&amp;quot;http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx&amp;quot;&amp;gt;loader&amp;lt;/a&amp;gt; &amp;lt;a href=&amp;quot;http://blogs.msdn.com/cbrumme/archive/2003/08/20/51504.aspx&amp;quot;&amp;gt;lock&amp;lt;/a&amp;gt; when calling &amp;lt;code&amp;gt;DllMain()&amp;lt;/code&amp;gt;...</description></item><item><title>Never, never ever call TerminateThread</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#253261</link><pubDate>Sat, 06 Nov 2004 12:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:253261</guid><dc:creator>Martin's WebLog</dc:creator><description /></item><item><title>Sharing my thoughts&amp;#8230;  &amp;raquo; Blog Archive   &amp;raquo; DllMain: Inadvertent deadlock</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#648446</link><pubDate>Tue, 27 Jun 2006 15:39:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:648446</guid><dc:creator>Sharing my thoughts…  » Blog Archive   » DllMain: Inadvertent deadlock</dc:creator><description>PingBack from &lt;a rel="nofollow" target="_new" href="http://sarathc.wordpress.com/2006/06/27/dllmain-inadvertent-deadlock/"&gt;http://sarathc.wordpress.com/2006/06/27/dllmain-inadvertent-deadlock/&lt;/a&gt;</description></item><item><title>Ice 'hangs' in destroy when called through DLL - ZeroC Forums</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/01/28/63880.aspx#9001785</link><pubDate>Thu, 16 Oct 2008 16:17:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9001785</guid><dc:creator>Ice 'hangs' in destroy when called through DLL - ZeroC Forums</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.zeroc.com/forums/help-center/3991-ice-hangs-destroy-when-called-through-dll.html#post17578"&gt;http://www.zeroc.com/forums/help-center/3991-ice-hangs-destroy-when-called-through-dll.html#post17578&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>