Home > Archive > VC Language > June 2005 > CriticalSection v/s Mutex
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
CriticalSection v/s Mutex
|
|
| msnews.microsoft.com 2005-06-09, 8:59 pm |
| Just a small question: What is the practical difference in using a
CriticalSection v/s a Mutex? (The Win32 implementation, not the MFC classes)
Atly.
Alvaro Palma
| |
| SledgeHammer 2005-06-09, 8:59 pm |
| CriticalSection are per Process for synchronization between Threads in one
Process. A Mutex can be shared between Processes.
"msnews.microsoft.com" wrote:
> Just a small question: What is the practical difference in using a
> CriticalSection v/s a Mutex? (The Win32 implementation, not the MFC classes)
>
> Atly.
> Alvaro Palma
>
| |
| Doug Harrison [MVP] 2005-06-09, 8:59 pm |
| On Thu, 9 Jun 2005 12:35:04 -0700, SledgeHammer wrote:
> "msnews.microsoft.com" wrote:
>
>
> CriticalSection are per Process for synchronization between Threads in one
> Process. A Mutex can be shared between Processes.
Also, CRITICAL_SECTION objects can be more efficient, as they don't require
a transition to kernel mode if there's no contention. You can think of a
"critical section" as a lightweight mutex with an unfortunate name, because
the region of code protected by a mutex is what a "critical section" is, at
least when using standard OS terms.
--
Doug Harrison
Microsoft MVP - Visual C++
| |
| Carl Daniel [VC++ MVP] 2005-06-09, 8:59 pm |
| msnews.microsoft.com wrote:
> Just a small question: What is the practical difference in using a
> CriticalSection v/s a Mutex? (The Win32 implementation, not the MFC
> classes)
CriticalSection is a user-mode component implemented by the Win32 subsystem,
while Mutex is a kernel-mode component.
Practially, CriticalSection is much faster when there's no actual blocking
(due to reduction in user-kernel mode switches), and probably slower when
there is blocking (due to more complex implementation). Additionally, since
a Mutex is represented by a HANDLE, you can wait on a mutex with a timeout,
or with several other handles. Neither option is available with a Critical
Section. Mutexes can be named and shared between processes, while
CriticalSections are restricted to the threads of a single process.
-cd
|
|
|
|
|