Showing archive results for 2011

Apr 12, 2011
Post comments count0
Post likes count0

Overheard conversation fragment: I'm over here by the slot machines

Raymond Chen

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 major hotels. She said, "I'm over here by the slot machines." Yeah, that narrows it down. I'll be heading to Vegas for the Niney Awards. If I don't ...

Non-Computer
Apr 12, 2011
Post comments count0
Post likes count1

Lock-free algorithms: The try/commit/(try again) pattern

Raymond Chen

The singleton constructor pattern and the 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 this pattern has a real name, but that's what I'm calling it for today. The general form of this pattern goes like this: We calculate the desired new value based ...

Code
Apr 11, 2011
Post comments count0
Post likes count1

Holding down the shift key when right-clicking lets you pin things to the Start menu even when you might have been better off not doing so

Raymond Chen

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 menu. What is this doing as an extended command? The Pin to Start menu command normally appears on the context menu of a program or a shortcut to a pr...

History
Apr 8, 2011
Post comments count0
Post likes count1

Lock-free algorithms: The singleton constructor (answer to exercises)

Raymond Chen

A few days ago, I asked you to make an existing class multithread-safe. The class caches objects called which are indexed by a 32-bit ID. The cache is implemented as an array that dynamically resizes as more items are added to it. A naïve multithreaded version might use a slim reader-writer lock with shared access on reads, exclusive access...

Code
Apr 7, 2011
Post comments count0
Post likes count1

Lock-free algorithms: The one-time initialization

Raymond Chen

A special case of the singleton constructor is simply lazy-initializing a bunch of variables. In a single-threaded application you can do something like this: This works fine in a single-threaded program, but if the program is multi-threaded, then two threads might end up trying to lazy-initialize the variables, and there are race conditions w...

Code
Apr 6, 2011
Post comments count0
Post likes count1

Lock-free algorithms: Choosing a unique value (solutions)

Raymond Chen

Last time, I left a warm-up exercise consisting of a code fragment which tries to compute a unique process-wide value. Here it is again: It may be easier to enumerate what the function does right rather than what it does wrong. Um, the words are correctly-spelled. That's about it. Damien was the first to note that the author basically...

Code
Apr 6, 2011
Post comments count0
Post likes count1

Lock-free algorithms: The singleton constructor

Raymond Chen

The first half may be familiar to many (most?) readers, but there's an interesting exercise at the bottom. A very useful pattern for the Interlocked* functions is lock-free lazy initialization via . Yes, that's a really long function name, but it turns out every part of it important. This is a double-check lock, but without the locking. Inste...

Code
Apr 5, 2011
Post comments count0
Post likes count1

Lock-free algorithms: Choosing a unique value (warm-up)

Raymond Chen

Here's a snippet of code whose job is to generate a unique number within the process. Here's some reference reading to get yourself in the mood. Caution: It may or may not be useful. Criticize this code fragment.

Code
Apr 4, 2011
Post comments count0
Post likes count1

Windows is not a .NET Framework delivery channel either

Raymond Chen

We learned a while ago that Windows is not an MFC delivery channel. And, since you asked, it's not a .NET Framework delivery channel either. If you're developing a program that uses the .NET Framework, you have to have a backup plan if the version of the .NET Framework you need is not installed on the computer. This might mean including a copy o...

Code