|Ned Batchelder : Blog | Code | Text | Site|
Mutexes and critical sections
» Home : Blog : April 2003
I'm annoyed by the fact that Win32 has two separate synchronization primitives, one called a mutex, and another called a critical section. I'm annoyed because these two work exactly the same, except one can be used across processes, and is therefore more heavyweight, than the other. Except for that, they are the same.
So why were they given those names? These are both mutexes. The name "critical section" doesn't even make any sense for an allocated object that can be locked and unlocked. What is it a section of, and in what sense is it critical?
The name "critical section" comes from the concurrent programming idea of a chunk of code that cannot be entered simultaneously by more than one thread. It is a critical section of code. Of course, a mutex is a good way to protect a critical section, and critical sections need not be protected across processes, so you can see how the term came to be misused for a lightweight mutex.
The Win32 definition of the term is being presented as authoritative in some glossaries, which is unfortunate. If you've learned about thread programming on Win32, try to remember: Microsoft's names for these things are a little off.