Post by Jeff FI was under the impression that there are semantic differences between
CCriticalSection and CMutex. One property is that CMutex allows recursive
locks from the same thread, whereas CCriticalSection blocks(deadlocks) when
recursively locked from the same thread. Am I mistaken?
They're both recursive. The differences between the Windows mutex object and
CRITICAL_SECTION don't apply to your problem, but for the record, they are:
1. The Mutex is a kernel object, represented by a HANDLE, while
CRITICAL_SECTION is not.
2. The other differences mainly follow from (1). For instance, you can use a
Mutex with WaitForSingleObject and friends, but this is not possible for
CRITICAL_SECTION. (NB: One of several design flaws in this part of MFC allow
you to use CCriticalSection with the MFC lock classes, but debug builds will
assert if you try this.) Mutexes can be named and used across processes,
while neither is possible for CRITICAL_SECTION. Locking a mutex requires
dropping into kernel mode, while locking a currently unacquired
CRITICAL_SECTION does not. And so on. For these reasons, a CRITICAL_SECTION
can be thought of as a lightweight mutex. (I wish they had named it
accordingly. :)
--
Doug Harrison
Microsoft MVP - Visual C++