Patterns for using the InitOnce functions
Since writing lock-free code is is such a headache-inducer, you're probably best off making some other people suffer the headaches for you. And those other people are the kernel folks, who have...
View ArticleHolding down the shift key when right-clicking lets you pin things to the...
Holding the shift key when calling up a context menu is a convention for indicating that you want to see additional advanced options which are normally hidden. One of those options is Pin to Start...
View ArticleLock-free algorithms: The try/commit/(try again) pattern
The singleton constructor pattern and the InterlockedMultiply example we saw some time ago are really special cases of the more general pattern which I'll call try/commit/(try again). I don't know if...
View ArticleOverheard conversation fragment: I'm over here by the slot machines
While on a trip to Las Vegas, I happened to overhear a woman talking on her mobile phone who, from her body language, was clearly trying to meet up with a friend. We were in the casino of one of the...
View ArticleLock-free algorithms: Update if you can I'm feeling down
A customer was looking for advice on this synchronization problem: We have a small amount of data that we need to share among multiple processes. One way to protect the data is to use a spin lock....
View ArticleLock-free algorithms: The opportunistic cache
Suppose profiling reveals that a specific calculation is responsible for a significant portion of your CPU time, and instrumentation says that most of the time, it's just being asked to calculate the...
View ArticleLock-free algorithms: The try/commit/(hand off) model
The last lock-free pattern for this week isn't actually lock-free, but it does run without blocking. The pattern for what I'll call try/commit/(hand off) is more complicated than the other patterns,...
View ArticleDon't forget to include the message queue in your lock hierarchy
In addition to the loader lock, the message queue is another resource that people often forget to incorporate into their lock hierarchy. If your code runs on a UI thread, then it implicitly owns the...
View ArticleBack from Las Vegas, and now my clothes smell like cigarette smoke
I actually came back Thursday night, but I've been too lazy to jot down some reactions until now. There are signs on the street directing you to a tram connecting the Monte Carlo hotel with the...
View ArticleVisual Studio 2005 gives you acquire and release semantics for free on...
If you are using Visual Studio 2005 or later, then you don't need the weird InterlockedReadAcquire function because Visual Studio 2005 and later automatically impose acquire semantics on reads from...
View ArticleEndorsement: Aaron Margosis's Unintended Consequences of Security Lockdowns...
At TechEd 2011 North America in Atlanta, Aaron Margosis is presenting a talk on Unintended Consequences of Security Lockdowns. I've seen the internal version of his talk and I give it two thumbs up....
View ArticleCorrections to Patterns for using the InitOnce functions
Adam Rosenfield pointed out that it is not possible to fail an asynchronous initialization; if you pass INIT_ONCE_INIT_FAILED when completing an asynchronous initialization, the function fails with...
View ArticleThe performance improvements of a lock-free algorithm is often not in the...
GWO wonders what the conditions are under which the lock-free version significantly outpeforms a simple critical section. Remember that switching to a lock-free algorithm should be guided by...
View ArticleEven if you have a lock, you can borrow some lock-free techniques
Even if you prefer to use a lock (after all, they are much easier to program), you can borrow some lock-free techniques. For example, consider this: CRITICAL_SECTION g_cs; GORILLADATA g_data; void...
View ArticleThere's only so much you can do to stop running code from simulating UI actions
Commenter KiwiBlue asks whether Captcha-style tests were considered to prevent unsigned drivers from programmatically clicking the 'Install anyway' button. I'm sure somebody considered it, but Captcha...
View ArticleNo, you can't ask whether your notification icon is visible or not
A customer asked what started out as a simple question, but by now you know that this sort of simple question only raises new questions: Is there a way that we can detect that the user has hidden our...
View ArticleHow do I pin a program directly to the Start menu rather than a shortcut?
Anonymous bemoans the fact that pinning programs to the Start menu (in Windows XP) actually pins the shortcut rather than the program itself. This means that if you right-click on a shortcut to pin...
View ArticleMicrospeak: Hipo
A friend of mind was asked out of the blue, "What does hypo mean?" She started to flash back to high school English class and Greek word roots. "I've started to hear it everywhere. Like Everyone in...
View ArticleWhy is there a RestoreLastError function that does the same thing as...
Matt Pietrek noticed that SetLastError and RestoreLastError do exactly the same thing and wondered why there's a separate function for it. It's to assist in debugging and diagnostics. Say you're...
View ArticleNot quite understanding why you wash your hands before playing the piano
My niece wanted to play my piano, and I asked her to wash her hands. She said, "I don't need that, I have Magic Soap," and she produced a bottle of hand sanitizer. Um, the purpose of washing your...
View Article