Joe Duffy's Blog

  • October 17, 2006
  • CLR locks and shutdown
  • The CLR’s approach to monitor acquisition (i.e. Monitor.Enter and Monitor.Exit) during shutdown is very different from native CRITICAL_SECTIONs and mutexes ( as described in my last post). In particular, the CLR does not ensure requests to acquire monitors on the shutdown path succeed, preferring instead to cope with the risk of deadlock rather than the risk of broken state invariants.

  • October 14, 2006
  • Ignoring lock acquisition during (native) shutdown
  • When a Windows process shuts down, one of the very first things to happen is the killing of all but one thread. This sole remaining thread is then responsible for performing shutdown duties, both in kernel and in user mode, including executing the appropriate DLL_PROCESS_DETACH notifications for the DLLs loaded in the process. A great treatise on shutdown and the associated subtleties can be found on, of course, Chris Brumme’s weblog.

  • October 3, 2006
  • Shared memory programming models -- it's just a name
  • I am often confronted with the question of whether concurrency programming models that employ shared memory are particularly problematic. I was asked this question directly on the concurrency panel at JAOO’06 earlier this week, for instance, and STM makes a big bet that such models are tenable.

  • September 22, 2006
  • New app responsiveness article in Dr. Dobb's
  • An article I wrote (seemingly ages ago) just appeared in the September issue of Dr. Dobb’s journal:

  • September 13, 2006
  • Hello PLINQ
  • LINQ coaxes developers into writing declarative queries that specify what is to be computed instead of how to compute the results. This is in contrast to the lion’s share of imperative programs written today, which are huge rat nests of for-loops, switch statements, and function calls. The result of this new direction? Computationally intensive filters, projections, reductions, sorts, and joins can be evaluated in parallel… transparently… with little-to-no extra input from the developer. The more data the better.

  • August 22, 2006
  • Priority-induced starvation: Why Sleep(1) is better than Sleep(0) and the Windows balance set manager
  • A common technique to avoid giving up your time-slice on multi-CPU machines is to use a hand-coded spin wait. This is appropriate when the cost of a context switch (4,000+ cycles) and ensuing cache effects are more expensive than the possibly wasted cycles used for spinning, which is to say not terribly often. When used properly, however, very little time is spent spinning, and the spin wait is only ever invoked rarely when very specific cross-thread state is seen, such as lock-free code observing a partial update. There are some best practices that must be followed when writing such a spin wait to guarantee good behavior across different machine configurations, i.e. HT, single-CPU, and multi-CPU systems.

  • August 21, 2006
  • Don't lock on marshal-by-bleed objects
  • [Update - 8/22/06 - fixed typos and paid homage to VSTS 2005’s code analysis which checks for this problem.]

  • August 13, 2006
  • Algorithms: Bloom filters
  • I’ve run across several algorithms lately that have benefited from the use of a Bloom filter. This led me to dig up the original paper ( Space/time trade-offs in hash coding with allowable errors) in which the idea was proposed. What surprised me a little was that this technique was invented 35 years ago, by a fellow by the name of Burton Bloom, and yet it remains a simple and effective way to speed up a certain category of modern software problems.

  • August 6, 2006
  • A fun hack: Cross-process RWLock using Windows kernel objects
  • This falls into the “fun hacks” category, meaning the result is not necessarily something you’d want to use in your everyday life. To go a step further, I strongly recommend you don’t use the code shown here as-is ; read the summary at the end for some rationale behind that statement. Enough with the disclaimer. On with the show…

  • August 3, 2006
  • 32-core Intel processors in 2010?
  • A glimpse of the future?