Hi All,
It is not quite clear from the MSDN documentation, if the callback for a
work item queued by IoQueueWorkItem is guaranteed to be executed in the
context of only one system thread, or it could be executed in any system
thread.
I.e is there dedicated system thread for work items (One for each
QueueType), or any system thread can do it?
For example I call IoQueueWorkItem several times in a row with different
work items. All the work items have the same callback routine and QueueType
for IoQueueWorkItem() is always DelayedWorkQueue. Will the callback be
executed in the context of only one system thread, or WorkItemA can be
executed in SystemThreadA and WorkItemB can be executed in SystemThreadC.
Do NT, 2000 and XP share the same behavior in that regard?
Thanks,
Danail Kirov
Danail,
There can be more than one thread to service work items for each
QueueTypes. The exact number varies depending on the amount of memory
the machine has.
I just broke into one of my test machines that has 256MB of RAM, and it
was 12 threads for the critical work queue, 3 for the delayed work
queue, and 1 for the hypercritical work queue. You driver should be
coded to handle the fact that your workitems could be processed in
parallel by different worker threads.
The debugger command “!exqueue” can be very helpful when you need to
look at what work is being done by the various worker queues. Check out
the debugger documentation for more details.
Molly Brown
Microsoft Corporation
This posting is provided “AS IS” with no warranties and confers no
rights.
-----Original Message-----
From: Danail Kirov [mailto:xxxxx@vertical.com]
Sent: Friday, January 31, 2003 1:49 PM
To: File Systems Developers
Hi All,
It is not quite clear from the MSDN documentation, if the callback for a
work item queued by IoQueueWorkItem is guaranteed to be executed in the
context of only one system thread, or it could be executed in any system
thread.
I.e is there dedicated system thread for work items (One for each
QueueType), or any system thread can do it?
For example I call IoQueueWorkItem several times in a row with different
work items. All the work items have the same callback routine and
QueueType for IoQueueWorkItem() is always DelayedWorkQueue. Will the
callback be executed in the context of only one system thread, or
WorkItemA can be executed in SystemThreadA and WorkItemB can be executed
in SystemThreadC.
Do NT, 2000 and XP share the same behavior in that regard?
Thanks,
Danail Kirov
You are currently subscribed to ntfsd as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
You cannot assume that all work items will be processed in the same
thread. There is a pool of threads (I believe based on the number of
processors) that will service the work queue. I am not sure what thread
specific knowledge (i.e. context) you are depending on (processor
affinity - for cache optimization etc.), but you should not assume
anything about the work item thread - other than that it will be running
in a different address space than your original request (not always the
case - but typically is) and has elevated rights (running in the SYSTEM
security context). For filter developers, you may also have to deal
with work queue exhaustion - wherein you block a request already
serviced on the work queue and wait for your request - also being
serviced on the work queue. For this reason, some filter developers
avoid using the operating system work queue.
/TomH
-----Original Message-----
From: Danail Kirov [mailto:xxxxx@vertical.com]
Sent: Friday, January 31, 2003 4:49 PM
To: File Systems Developers
Subject: [ntfsd] IoQueueWorkItem
Hi All,
It is not quite clear from the MSDN documentation, if the callback for a
work item queued by IoQueueWorkItem is guaranteed to be executed in the
context of only one system thread, or it could be executed in any system
thread.
I.e is there dedicated system thread for work items (One for each
QueueType), or any system thread can do it?
For example I call IoQueueWorkItem several times in a row with different
work items. All the work items have the same callback routine and
QueueType
for IoQueueWorkItem() is always DelayedWorkQueue. Will the callback be
executed in the context of only one system thread, or WorkItemA can be
executed in SystemThreadA and WorkItemB can be executed in
SystemThreadC.
Do NT, 2000 and XP share the same behavior in that regard?
Thanks,
Danail Kirov
You are currently subscribed to ntfsd as: xxxxx@inflectionsystems.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
There is a good discussion of this here:
http://www.osr.com/ntinsider/1998/work%20queues.htm
According to this doc there are “something like” 3
threads to service items in the DelayedWorkQueue. I
believe that this article is talking about NT 4. 2000
and XP may have more.
What is your concern about running in different
contexts? All of these threads run in the same
process context so things like a handle value in one
would still be valid in another.
Randy Cook
— Danail Kirov wrote:
> Hi All,
> It is not quite clear from the MSDN documentation,
> if the callback for a
> work item queued by IoQueueWorkItem is guaranteed to
> be executed in the
> context of only one system thread, or it could be
> executed in any system
> thread.
> I.e is there dedicated system thread for work items
> (One for each
> QueueType), or any system thread can do it?
>
> For example I call IoQueueWorkItem several times in
> a row with different
> work items. All the work items have the same
> callback routine and QueueType
> for IoQueueWorkItem() is always DelayedWorkQueue.
> Will the callback be
> executed in the context of only one system thread,
> or WorkItemA can be
> executed in SystemThreadA and WorkItemB can be
> executed in SystemThreadC.
>
> Do NT, 2000 and XP share the same behavior in that
> regard?
>
> Thanks,
>
> Danail Kirov
>
>
>
> —
> You are currently subscribed to ntfsd as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
xxxxx@lists.osr.com
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
> I.e is there dedicated system thread for work items (One for each
QueueType), or any system thread can do it?
There is a pool of system threads for work items, and you do not know
what of them will execute your item.
Max
There are a fixed number of worker threads for each class of system worker
queue. Under Windows NT4, only file systems should use the system queues or
you can create deadlocks. The best way is to use your own thread to service
your queue and then you don’t have to worry about any changes Microsoft may
make. Your thread can maintain file handles that will remain valid as each
work item is processed, however this is not true for system threads since
you can’t know which one will be used.
The NT Insider had a very good article several years ago about writing your
own worker thread queues. I implemented it several times using their logic
and it always works. You can have more than one thread to process work
items for single queue, but in all my code only one was used. If you use
more than one worker thread, then maintaining an open file or some other
object that is thread/process specific might be a problem. It only takes a
few lines of code to implement. DriverWorks already includes such support,
but they don’t queue work items if the current IRQL is APC_LEVEL, so I had
to modify their code to force all non-PASSIVE_LEVEL requests to the worker
thread. Simple logic, well written, even if limited by the APC_LEVEL bug
and modification only affected four lines.
----- Original Message -----
From: “Maxim S. Shatskih”
To: “File Systems Developers”
Sent: Saturday, February 01, 2003 1:35 PM
Subject: [ntfsd] Re: IoQueueWorkItem
> > I.e is there dedicated system thread for work items (One for each
> > QueueType), or any system thread can do it?
>
> There is a pool of system threads for work items, and you do not know
> what of them will execute your item.
>
> Max
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@yoshimuni.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com