Re: User vs. Worker threads



If a driver creates a thread with PsCreateSystemThread() and uses NULL then
you are correct.

According to MSDN, this is how drivers are supposed to do things......



Anton Bassov

On Jan 26, 6:52 am, "David J. Craig" <D...@xxxxxxxxxxxxx> wrote:
1. The internal name on Windows XP Pro SP2 is null. The query returns a
buffer of all zeroes (binary). The 'System' process name is given to PID 4
in the same OS. It has all the worker threads.

If a driver creates a thread with PsCreateSystemThread() and uses NULL then
you are correct. If it uses the NtCurrentProcess() macro, it is created in
the current caller's process if the thread has PROCESS_CREATE_THREAD access
to this process. Any other process ID can be used if the thread has that
permission. If you want to have your worker thread reference an event
passed in from user mode you can give it process access with the macro and
it just works.

"anton bassov" <soviet_bl...@xxxxxxxxxxx> wrote in messagenews:1169789813.832058.157550@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



Kevin,

Basically, you got it right. Congratulations!!!! However, a couple of
amendments are still needed.

As far as kernel concerned, there are 3 types of threads:

1. Idle threads, i.e. the ones that CPU dispatches when it has no other
threads to dispatch. Every CPU has its own idle thread. Collection of
idle threads is known as a System Idle Process (this is how it is known
to the Task Manager - its internal name is just System, and its PID is
zero). Idle threads cannot get terminated, for understandable reasons

2. Worker threads. These threads run tasks that are not directly
related to user requests, and, hence, have no user-mode representation.
"Lazy writer" thread and Balance Set Manager are typical examples of
worker threads. Collection of worker threads is known as System Process
(its PID is non-zero). Worker threads cannot be terminated by external
means, although they can terminate themselves by calling
PsTerminateSystemThread()

3. All threads that are neither worker nor idle ones are referred to as
user threads. These threads have their user-mode representation, and
can get
terminated both externally and upon their own initiative. In former
case the target thread may get terminated only if it is able to receive
user-mode APCs
( i.e. the thread is currently in the user mode or in the waiting state
with 'UserMode' having been specified as WaitMode' parameter to
KeWait... call). Otherwise, the thread will be terminated only after it
makes a return to the user mode

If driver creates a thread in the kernel mode with
PsCreateSystemThread(), this thread will be a worker one - it will have
no user-mode representation, and run in context of a system process, no
matter in which context PsCreateSystemThread() has been made. However,
as any other thread, it just cannot "execute separate from the
IRQ-driven code" - when interrupt occurs,
it gets processed in context of arbitrary thread, i.e. the one that
happens to run on the given CPU at the time of interrupt, no matter if
this thread is worker or user or idle one....

Anton Bassov

On Jan 26, 3:25 am, "Kevin" <kevi...@xxxxxxxxxxx> wrote:
In case it is a non-MFC question, then:

A "user thread" is a thread that happens to be executing some arbitrary
thread from some arbitrary process, while in the kernel.

A "worker thread" is a thread created by device driver code in the
kernel,
to execute separate from the IRQ-driven code.

"William DePalo [MVP VC++]" <willd.no.s...@xxxxxxxx> wrote in
messagenews:uF64Lu9PHHA.1248@xxxxxxxxxxxxxxxxxxxxxxx

"e_yossi" <eyo...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:33E2CE27-947E-431B-9476-DE87A75A94C0@xxxxxxxxxxxxxxxx
What are the differences between worker threads
and user threads?

To the operating system, the threads in an _application_ are all the
same.

MFC's framework makes a distinction between threads which own windows
and
have message maps and which therefore spin message loops (UI threads)
and
threads that don't (worker threads). If you need further information on
MFC you should repost in one of the MFC groups.

Regards,
Will

www.ivrforbeginners.com-Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -

.



Relevant Pages

  • Re: User vs. Worker threads
    ... Drivers are better documented there ... It has all the worker threads. ... Idle threads cannot get terminated, ... although they can terminate themselves by calling ...
    (microsoft.public.win32.programmer.kernel)
  • Re: User vs. Worker threads
    ... It has all the worker threads. ... Idle threads, i.e. the ones that CPU dispatches when it has no other ... related to user requests, and, hence, have no user-mode representation. ... although they can terminate themselves by calling ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Handle STOP in a multi-threaded Windows service
    ... > I've written a Windows Service which has ... > - several listeners threads which spawn worker threads based on ... > Does Windows wait for all threads to terminate in a given timespan, ... issuing a Thread.Abort as part of the CLR's orderly shutdown procedure. ...
    (microsoft.public.dotnet.general)
  • Re: debugging web server with lmemdebug
    ... There is no graceful way to terminate httpdexe.exe. ... (HTTP worker threads in internal ... © 2003 Microsoft Corporation. ...
    (microsoft.public.windowsce.platbuilder)

Loading