user mode & kernel mode thread synchronization

user mode & kernel mode thread synchronization

Post by MK » Fri, 02 Jun 2006 18:52:43


What is ther difference between user mode & kernel mode thread
synchronization ?
when to use mutexes & when to use critical sections ??

Thanks in advance.
 
 
 

user mode & kernel mode thread synchronization

Post by Scott McPh » Sat, 03 Jun 2006 06:54:10


All things kernel mode are off limits to an application program and off
topic here.

Mutexes and critical sections are for synchronizing threads in user mode
(i.e. in application programs). They both perform the same synchronizng
function of making one thread suspend until another thread releases a
shared resource.

A critical section can be used only within a single process (i.e.
application). But a mutex can also be used to provide sync between
threads in different processes. The critical section is more efficient
if contention is infrequent.

--
Scott McPhillips [VC++ MVP]

 
 
 

user mode & kernel mode thread synchronization

Post by Joseph M. » Sat, 03 Jun 2006 23:50:30

Kernel mode: Spin Lock, Queued Spin Lock, Fast Mutex, Executive Resource, and Mutex
User mode: CRITICAL_SECTION, Mutex

Note that CRITICAL_SECTION is best for intra-process inter-thread synchronization,
providing you don't need to do a multiple wait, use a timeout, or recover from a deceased
thread that is holding the CRITICAL_SECTION. Mutex for inter-process synchronization, if
you need a waitable object (for multiple waits), need a timeout, or have to deal with
deceased threads. Kernel primitives, except KMUTEX, have no equivalents in user space and
therefore are irrelevant. And it is very dangerous to try to share a KMUTEX with user
space by wrapping it in a handle, or a Mutex with kernel space by having someone unwrap
the handle to get to the KMUTEX. Doing so will ultimately leave you blue. [And I mean
Blue Screen Of Death. Note that I teach kernel synchronization in my Device Driver
course. Nothing in kernel synchronization is applicable in user space]
joe



Joseph M. Newcomer [MVP]
email: XXXX@XXXXX.COM
Web: http://www.yqcomputer.com/
MVP Tips: http://www.yqcomputer.com/