Re: Mutex does not seem to lock
From: cristalink (cristalink_at_nospam.nospam)
Date: 12/14/04
- Next message: jujuman1818_at_yahoo.com: "Mutex does not seem to lock"
- Previous message: wenhua: "How many disk drives can Windows support"
- In reply to: jujuman1818_at_yahoo.com: "Mutex does not seem to lock"
- Next in thread: Maxim S. Shatskih: "Re: Mutex does not seem to lock"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 15 Dec 2004 12:47:23 +1300
(1) I guess that your ISR is called at an IRQL higher that DISPATCH_LEVEL.
If so, you can't use KeWaitForSingleObject, because it's allowed at IRQL <=
DISPATCH_LEVEL.
(2) I guess that an ISR can be called in the context of any thread,
including your UserThread that is currently
"operating on buffer". Since a mutex can be acquired recursively by the same
thread, the ISR called in the UserThread context will successfully acquire
the mutex already being held by UserThread, which is probably not what you
want. Normally, spinlocks are used for this kind of job.
(3) ISRs are not supposed to work on user buffers. They are supposed to
queue DPCs and exit as soon as possible.
-- http://www.firestreamer.com - NTBackup to DVD and DV <jujuman1818@yahoo.com> wrote in message news:1103053842.502899.164590@z14g2000cwz.googlegroups.com... >I am currently having problems with my locks on my mutex not being > obeyed. > > I have a function that is called from a DeviceIOControl to do some work > on behalf of it. This requires me to lock the user buffer into > non-pageable memory for potential use during an interrupt service > routine and perform some operations. The function follows something > like this: > > #define LOCK_MUTEX(timeout) > (KeWaitForMutexObject(&(mutex),Executive,KernelMode,FALSE,timeout)==STATUS_SUCCESS) > #define UNLOCK_MUTEX() KeReleaseMutex(&mutex,FALSE); > > KMUTEX mutex; > > void UserThread (buffer) > { > if LOCK_MUTEX(INFINITE) > { > Lock user buffer > Operate on buffer > UNLOCK_MUTEX(); > } > } > > void ISR (buffer) > { > LARGE_INTEGER zero = {0}; > if LOCK_MUTEX(&zero) > { > Check if buffer is valid > Operate on buffer > Release buffer > UNLOCK_MUTEX(); > } > } > > For the most part this works, however, every now and then I somehow > when I am operating on the buffer inside UserThread(), I enter the ISR, > operate on it and then release it. The problem then occurs on the > context switch back to UserThread() and it tries to operate on the > buffer. I get an access violation (bug check 8e). There are only these > two places that manipulate the mutex and the buffer. > > Using DbgPrint()'s I clearly see entering both functions even though > only one should be enterable at a time. If the ISR fails that may be > slightly problematic, but blue screens are unacceptable. > > The only thing I figure is that somehow I am not properly locking the > mutex, however after double checking with MSDN, everything looks fine. > > Is there someone wrong with the way I am doing this or a way to more > strongly enforce the mutex? > > Note, the code needs to work in both Win2k/XP and Win98 environments. > Thanks in advance, > Derrick Chu >
- Next message: jujuman1818_at_yahoo.com: "Mutex does not seem to lock"
- Previous message: wenhua: "How many disk drives can Windows support"
- In reply to: jujuman1818_at_yahoo.com: "Mutex does not seem to lock"
- Next in thread: Maxim S. Shatskih: "Re: Mutex does not seem to lock"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|