The Old New Thing

On the dangers of sharing your apartment

My colleague Marc Miller wrote up a brief essay on the subject of dealing with a neutral apartment that has been injected into your single-threaded apartment: COMmunism: Sharing your Apartment. Highly recommended...

Consequences of the scheduling algorithm: Sleeping doesn’t always help

More often I see the reverse of the "Low priority threads can run even when higher priority threads are running" problem. Namely, people who think that is a clean way to yield CPU. For example, they might have run out of things to do and merely wish to wait for another thread to produce some work. Recall that the scheduler looks for the ...

Consequences of the scheduling algorithm: Low priority threads can run even when higher priority threads are running

Just because you have a thread running at a higher priority level doesn't mean that no threads of lower priority will ever run. Occasionally, I see people write multi-threaded code and put one thread's priority higher than the other, assuming that this will prevent the lower-priority thread from interfering with the operation of the higher-...

On objects with a reference count of zero

One commenter claimed that When the object is first constructed, the reference count should be 0 and AddRef should be called at some point (probably via QueryInterface) to increment the reference count. If you construct your object with a reference count of zero, you are playing with matches. For starters, when the object is created, ...

Fiddling with the fonts, part 2: Keeping the English font small

We concluded last time that we wanted the custom large font to apply only to the columns containing Chinese characters and leave the original font in place for the English columns. We do this by carrying two fonts around, choosing the appropriate one for each column. class RootWindow : public Window { ... private: HWND m_hwndLV; HWND ...

Fiddling with the fonts, part 1: Making the Chinese characters larger

Let's pay a quick visit to our continuing dictionary project. One of the things you may have noticed is that the Chinese characters are unreadably small. Let's fix that by making them larger. class RootWindow : public Window { public: virtual LPCTSTR ClassName() { return TEXT("Scratch"); } static RootWindow *Create(); RootWindow(); ~...

Understanding the consequences of WAIT_ABANDONED

One of the important distinctions between mutexes and the other synchronization objects is that mutexes have owners. If the thread that owns a mutex exits without releasing the mutex, the mutex is automatically released on the thread's behalf. But if this happens, you're in big trouble. One thing many people gloss over is the ...