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.

tagged: , » 2 reactions

Comments

[gravatar]
Bob 1:31 PM on 18 Apr 2003

Naming is hard and its even harder to rename.

In retrospect, Microsoft should have called them something like "process" and "global" mutexs to make the distinction. Sun makes this sort of distinction with threads on Solaris -- there are "user" and "kernel" threads. The former is only for programmer convenience and not pre-emptive and can't be independently scheduled on different processors. Microsoft has made a similar weird name choice here: they have "threads" and "fibers". The latter are like "user threads" in Solaris.

--bob

[gravatar]
Ole Eichhorn 4:03 PM on 21 Apr 2003

No question, this is confusing. Especially because most people call such objects "semaphores", and Windows has an object called a semaphore, but it doesn't have the expected semantics. The first time I heard "Mutex" I thought it was a joke. (Yeah, mutually exclusive, I get it, but the name still sucks.) "Critical Section" is more descriptive but this is an unexpected usage.

Ole

Add a comment:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.