The Old New Thing

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 ...

Reading the output of a command from batch

The FOR command has become the batch language's looping construct. If you ask for help via FOR /? you can see all the ways it has become overloaded. For example, you can read the output of a command by using the for command. FOR /F "tokens=*" %i IN ('ver') DO echo %i The /F switch in conjunction with the single quotation marks indicates ...

Why aren’t low-level hooks injected?

When I described what the HINSTANCE parameter to the function is for, I neglected to mention why the low-level hooks are not injected. But then again, it should be obvious. The low-level hooks let you see input as it arrives at the window manager. At this low level of processing, the window manager hasn't yet decided what window will ...