Interview Test Question
-
I was asked, "If we have mutexes, why do we need critical sections?" My answer was that mutexes protect resources and critical sections protect code. Was I on the right track?
The difficult we do right away... ...the impossible takes slightly longer.
-
I was asked, "If we have mutexes, why do we need critical sections?" My answer was that mutexes protect resources and critical sections protect code. Was I on the right track?
The difficult we do right away... ...the impossible takes slightly longer.
Richard Andrew x64 wrote:
Was I on the right track?
You decide: Critical Section vs. Mutex - MSDN Blogs[^]
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
I was asked, "If we have mutexes, why do we need critical sections?" My answer was that mutexes protect resources and critical sections protect code. Was I on the right track?
The difficult we do right away... ...the impossible takes slightly longer.
I would think that in general, mutexes are purely kernel controlled objects whereas critical sections are mostly "user mode primitives", meaning it's application level logic most of the time (which runs a lot faster without requiring the kernel to be involved). Of course, this also implies a critical section is bound within a process and cannot be shared across processes. The exception is when there actually is a conflict, then a critical section makes a kernel call for synchronization. If you write some test code, you should be able to notice the speed advantage of a critical section (and all the kernel system calls of a mutex).