Gary is correct, you can acquire locks in work items. IIRC, the topic Pankaj is referring to states that you should not infinitely block in the work item, basically you should grab your lock, do your work, and then exit out in a timely fashion and not tie up the work item for a very long period of time since work items are a shared system resource.
d
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@seagate.com
Sent: Wednesday, March 08, 2006 1:09 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] IoCompleteRequest() from WorkItem
My reading of the DDK does not say that. It says that the driver should release any synchronization objects it holds before it calls IoQueueWorkItem. You are dealing with an IRP that quite frequently is completed by the DPC or a Cancel routine, and those are DISPATCH_LEVEL functions, so the best way to sync with them is via a spinlock … unless you write your own using an interlocked function, and that by definition is a pain in the ass. ?Acquiring a spinlock that protects an IRP is the only way I know of for a work item at PASSIVE to sync with a DPC at DISPATCH.
Gary G. Little
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Pankaj Garg
Sent: Wednesday, March 08, 2006 2:39 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] IoCompleteRequest() from WorkItem
Gary,
?
It is mostly recommended to not hold any locks in a work item. The DDK says it can cause deadlock and i agree to it but i haven’t enumerated various cases which can cause deadlock. Anyways since workitem is running on system thread, its better to not hold a lock because it may adversely affect system performance as well.
?
In my practice, i have always found a solution without using locks.
–
Pankaj Garg
This posting is provided “AS IS” with no warranties and confers no rights.
?
?
wrote in message news:xxxxx@ntdev…
You need to sync your work item at PASSIVE with other functions that can complete or cancel the IRP. The easiest way to do that, and is cross IRQL compatible, is to hold a spinlock any time the IRP is about to be manipulated; e.g. acquire the spinlock before you acquire the IRP. Cancel Safe Queues are great for this and KMDFs queuing mechanism appear to be even better.
Gary G. Little
________________________________________
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Zed y
Sent: Wednesday, March 08, 2006 2:05 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] IoCompleteRequest() from WorkItem
Hi
?
Lets say I’m in PASSIVE IRQL in a dispatch function.
I mark my irp as pending. Later, I create a workitem that receives the irp as a context and do some work in it. In the end of the workitem’s function, I complete the IRP.
Back to the dispatch routine - after allocating and queuing the workitem, I return STATUS_PENDING .
?
Now, because I’m in PASSIVE level, there can be a context switch from my dispatch routine to my workitem’s function, so it will run and complete the irp, before I return STATUS_PENDING from the dispatch routine. (it means that when I return STATUS_PENDING, the irp is already completed!)
?
Is there a problem with the above scenario?? And if so, how should I handle it?
?
thanks
— Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
—
Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
—
Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer