3 ms·
> Windows programmers were more familiar with “critical sections” as an abstraction than mutexes. I disagree on that front. Mutex kernel objects have existed j
by dblohm7 4y ago
> Windows programmers were more familiar with “critical sections” as an abstraction than mutexes.
I disagree on that front. Mutex kernel objects have existed just as long as critical sections. Critical section objects are cheaper because they don’t switch into the kernel when not contended.
- asveikau 4y agoA Win32 critical section enters the kernel when blocked. (Edit: nevermind, you're not disputing this) A pthread mutex on Linux won't enter the kernel when uncontended (thanks to futex -- this wasn't true ~20 years ago). I would say the terms are pretty synonymous, and implementation choices differ; sometimes implementation choices are implied by the name but I don't think everybody agrees on how those choices map to names.
- codeflo 4y agoThat’s only an implementation/optimization difference, I think it’s also relevant to understand why that’s the case. At the API level, the important distinction is that a Mutex an be shared between processes. This is great when you need it, but having the capability makes Mutexes have a somewhat expensive implementation. CriticalSections stay inside the process, so can be optimized for that (more common) use case.
- dblohm7 4y agoPrecisely.