May 18th, 2017

Why is the !locks command called !locks even though it debugs only critical sections?

Commenter DWalker07 notes that the !locks command is called !locks even though it doesn’t actually debug all types of locks, only critical sections. Why the bad name?

Because at the time it was written, critical sections were the only types of user-mode locks.

In the original incarnation of Win32, there were semaphores and mutexes and other kernel-mode synchronization objects, but the only user-mode synchronization objects were critical sections. Seeing as they were the only type of synchronization objects available in user mode, they were informally referred to as “locks” because when you have only one kind of thing, you don’t really worry too much about being specific.

If there’s only kind of wristwatch, then you don’t really bother being specific about the fact that it’s a spring-wound analog-readout time-only watch. You just call it a watch. Of course, later, when battery-powered digital-readout smart watches become commonplace, your old documents that talk about “watches” may seem confusing. “Why do these instructions for troubleshooting watches not work for my battery-powered digital-readout smart watch?”

Indeed, for a very long time, critical sections were the only user-mode synchronization objects that came with Win32. It wasn’t until Windows Vista that a whole bunch of new user-mode synchronization objects became available, things like slim reader-writer locks, condition variables, and one-time initialization. Until then, the word “lock” was sufficient.

Topics
History

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.