RSS 2.0

Personal Info:

Joe Send mail to the author(s) leads the architecture of an experimental OS's developer platform, where he is also chief architect of its programming language. His current mission is to enable writing large-scale software that is reliable, secure, and scalable by-construction. Before this, Joe founded the Parallel Extensions to .NET project. He has been granted 19 patents, with 49 pending. When not working, Joe enjoys travelling with his wife, writing books, writing music, studying music theory & mathematics, and doing anything involving food & wine.

My books

My music

Disclaimer:
The content of this site are my own personal opinions and do not represent my employer's view in anyway.

© 2012, Joe Duffy

 
 Saturday, November 18, 2006

I was surprised to find out that attempting to acquire an orphaned native "slim" reader/writer lock (SRWL) on the shutdown path hangs on Windows Vista.  Unlike orphaned critical section acquisitions during shutdown on Windows -- which, in Vista cause the process to terminate immediately, and pre-Vista enjoyed "weakening" to avoid deadlocking at the risk of seeing corrupt state -- SRWL's AcquireSRWLockXXX methods are not shutdown aware.

This is actually pretty dangerous, and effectively means you should stay as far away from SRWLs during shutdown as possible.  Avoiding synchronization and any sort of cross-thread coordination in DllMain is generally a good rule of thumb anyway, since it runs under the protection of the loader lock, has to tolerate very harsh conditions, and often runs w/out the presence of other active threads.

But this means something even stronger and sets SRWLs distinctly apart from Win32 critical sections.  If you're writing a reusable native library whose functionality somebody might conceivably want to use on the shutdown path, you really ought not to be using SRLWs internally.  If app developers don't realize you employ internal SRWL synchronization, they might call you and, every so often when the stars align, their users will experience a random hang during shutdown.  Library authors might consider giving TryXXX variants of their APIs so that developers can at least deal with the case in which a SRWL has been orphaned.

Notice that hanging is similar to managed code's approach to lock acquisitions during shutdown.  There's a big difference, though: the CLR anoints a shutdown watchdog thread that kills the process after 2 seconds when a hang occurs, whereas native code won't.  The native hang persists indefinitely.

I'd be a much happier guy if SRWLs mirrored the new Vista orphaned critical section shutdown behavior.

 

Recent Entries:

Search:

Browse by Date:
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910

Browse by Category:

Notables: