Worker Threads on NT and 2000

Hello all,

I have written a series of communication classes that provide
“communications” to our higher level developers. The issue I have is during
shutdown…

I have 4 worker threads. Each worker thread has several events that they
monitor using WaitForMultipleObjects() -

When the Application/Service starts it’s cleanup to terminate I set an event
“Die” (each thread has it’s own ‘DIE’ and ‘ThreadIsDead’ event objects) and
the worker thread starts it’s shutdown… I then
WaitForSingleObject(ThreadIsDead) for the thread to single that it has
completed it’s shutdown… I have a timeout of 5 seconds, occasionally I
don’t get signaled from the worker thread that it has died and I let the
service/application terminate.

Is there any side effects of letting the application terminate before the
threads are completed stoped? All other resources (Memory, Sockets, Files,
etc) are closed and free, it is only the worker thread…

Thanks in advance for your reply…

Jim Row
Senior Software Engineer
Extended Technologies Corporation
9708 Skillman Road
Dallas, TX 75243

EMAIL: xxxxx@xtekcorp.com
PHONE: 214-540-4117
FAX: 214-540-40


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> When the Application/Service starts it’s cleanup to terminate I set an
event

“Die” (each thread has it’s own ‘DIE’ and ‘ThreadIsDead’ event objects)
and
the worker thread starts it’s shutdown… I then
WaitForSingleObject(ThreadIsDead) for the thread to single that it has
completed it’s shutdown… I have a timeout of 5 seconds, occasionally I
don’t get signaled from the worker thread that it has died and I let the
service/application terminate.

Make INFINATE in WaitForSingleObject and Try once.

Is there any side effects of letting the application terminate before the
threads are completed stoped?

Not Advisable.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

No point in having a “threadisdead” event – all events have a handle that is
signalled when the thread has completed – use that and save resources.

There are no side effects of ending a process eg ExitProcess(0) naturally – NT
will do a very clean shutdown of all all resources/threads for you. It’s not an
“elegant” solution, but it doesn’t do any harm either. The only caution is to
know what your threads might be doing – if they’ve created a “marker file” for
example that is normally deleted on thread exit, then this file will still exist
after process exit. But, if you know what your worker threads are doing, then
don’t bother asking/waiting for them to quit – just ExitProcess and let NT do it
all for you. The API to avoid is TerminateThread/TerminateProcess – this can
cause leaks and should not be the “normal” way to force a thread/process to exit.

Regards,

Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com

-----Original Message-----
From: Jim Row [mailto:xxxxx@xtekcorp.com]
Sent: Friday, May 25, 2001 7:38 AM
To: NT Developers Interest List
Subject: [ntdev] Worker Threads on NT and 2000

Hello all,

I have written a series of communication classes that provide
“communications” to our higher level developers. The issue I have is during
shutdown…

I have 4 worker threads. Each worker thread has several events that they
monitor using WaitForMultipleObjects() -

When the Application/Service starts it’s cleanup to terminate I set an event
“Die” (each thread has it’s own ‘DIE’ and ‘ThreadIsDead’ event objects) and
the worker thread starts it’s shutdown… I then
WaitForSingleObject(ThreadIsDead) for the thread to single that it has
completed it’s shutdown… I have a timeout of 5 seconds, occasionally I
don’t get signaled from the worker thread that it has died and I let the
service/application terminate.

Is there any side effects of letting the application terminate before the
threads are completed stoped? All other resources (Memory, Sockets, Files,
etc) are closed and free, it is only the worker thread…


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Thanks Paul…

-----Original Message-----
From: Paul Bunn [mailto:xxxxx@UltraBac.com]
Sent: Friday, May 25, 2001 10:46 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Worker Threads on NT and 2000

No point in having a “threadisdead” event – all events have a handle that
is
signalled when the thread has completed – use that and save resources.

There are no side effects of ending a process eg ExitProcess(0) naturally –
NT
will do a very clean shutdown of all all resources/threads for you. It’s
not an
“elegant” solution, but it doesn’t do any harm either. The only caution is
to
know what your threads might be doing – if they’ve created a “marker file”
for
example that is normally deleted on thread exit, then this file will still
exist
after process exit. But, if you know what your worker threads are doing,
then
don’t bother asking/waiting for them to quit – just ExitProcess and let NT
do it
all for you. The API to avoid is TerminateThread/TerminateProcess – this
can
cause leaks and should not be the “normal” way to force a thread/process to
exit.

Regards,

Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com

-----Original Message-----
From: Jim Row [mailto:xxxxx@xtekcorp.com]
Sent: Friday, May 25, 2001 7:38 AM
To: NT Developers Interest List
Subject: [ntdev] Worker Threads on NT and 2000

Hello all,

I have written a series of communication classes that provide
“communications” to our higher level developers. The issue I have is during
shutdown…

I have 4 worker threads. Each worker thread has several events that they
monitor using WaitForMultipleObjects() -

When the Application/Service starts it’s cleanup to terminate I set an event
“Die” (each thread has it’s own ‘DIE’ and ‘ThreadIsDead’ event objects) and
the worker thread starts it’s shutdown… I then
WaitForSingleObject(ThreadIsDead) for the thread to single that it has
completed it’s shutdown… I have a timeout of 5 seconds, occasionally I
don’t get signaled from the worker thread that it has died and I let the
service/application terminate.

Is there any side effects of letting the application terminate before the
threads are completed stoped? All other resources (Memory, Sockets, Files,
etc) are closed and free, it is only the worker thread…


You are currently subscribed to ntdev as: xxxxx@xtekcorp.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com