Can you Hold a Mutex while Sending a Request Down the Stack

I have seen where they say you should not hold a spin lock while calling outside of the driver, but can you hold a mutex and send an ACPI eval request down the stack?

I have access information that timer maintains in its context which can be switched, but I don’t want it switched while it is processing the callback. I am thinking about using some sort of synchronization object to do this, but I am not sure I can hold a kernel object while I send the request down the stack.

Input is welcome. Thanks…

The guidance around the spinlock, and holding any lock really, is around reentrancy and trying to acquire the same lock in the completion routine when the irp is completed synchronously. Deadlock ensues.

d

Bent from my phone


From: xxxxx@intel.commailto:xxxxx
Sent: ?11/?11/?2013 7:19 PM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: [ntdev] Can you Hold a Mutex while Sending a Request Down the Stack

I have seen where they say you should not hold a spin lock while calling outside of the driver, but can you hold a mutex and send an ACPI eval request down the stack?

I have access information that timer maintains in its context which can be switched, but I don’t want it switched while it is processing the callback. I am thinking about using some sort of synchronization object to do this, but I am not sure I can hold a kernel object while I send the request down the stack.

Input is welcome. Thanks…


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

The best synchronization is no synchronization.

By this, I mean that the ideal architectures are those which do not
require concureent access to resources. This is not always easy to
achieve, and, in te case of spinlocks, often it is impossible to create
such a solution. There is no particular intrinsic problem with holding a
mutex, because you are already at PASSIVE_LEVEL. The issue of reentrancy
that has been alluded to is serious in another direction. If you hold a
spinlock, and fid yourself needing to acquire it before you can release
it, then you have deadlock. In the case of a mutex, you have an
additional problem. Suppose you acquire the mutex in thread T1, and then
need to acquire it again in T2, before you can complete the action. Boom.
Deadlock. But suppose we have our shared structure in an inconsistent
state, and thread T1 has acquired te mutex. T1 comes along, tries to
acquire the mutex, and because of te recursive acquisition properties of
mutice, just goes barrelling through and does not stop, and ends up
working on a data structure whose integrity has been (temporarily)
compromised.

Synchronization represents places where two threads touch, that is, where
there is friction. And like friction in physical systems, all this does
is generate heat and waste energy.

It always loos easy to throw a mutex in to solve a concurrent access
problem, but I’ve learned over the years that, insofar as it is possible,
to avoid conditions in which synchronization is not required. If it is
necessary to serialize access to te ACPI actions, and you have no
potential conflicts with reentrancy, and you are guaranteed that you are
at PASSIVE_LEVEL, then you probably won’t have a problem. Note, however,
that if your PASSIVE_LEVEL thread is the application thread, you have the
potential of messing up an app that is relying on async I/O to not block.

Can you say more about why you need to block?
joe

I have seen where they say you should not hold a spin lock while calling
outside of the driver, but can you hold a mutex and send an ACPI eval
request down the stack?

I have access information that timer maintains in its context which can be
switched, but I don’t want it switched while it is processing the
callback. I am thinking about using some sort of synchronization object
to do this, but I am not sure I can hold a kernel object while I send the
request down the stack.

Input is welcome. Thanks…


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer