15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Thread programming issue

Anita Yadav CS -- ayadav@grad.csee.usf.edu
Friday, April 05, 1996

Hi everyone,
  I am using VC++ 4.0 to develop an SDI application for NT 3.51.  My
  application spawns several threads and two background programs.  My
question is : before exiting the application how can I check if my
threads have terminated.  I can check Exit status of individual threads
but keeping track of individual thread handles seems cumbersome.  Is
there an effective way to do this task?  Also, do I have to release
individual thread handles before the application terminates?

Any help will be appreciated.
Thanks.
Anita.
ayadav@csee.usf.edu



Mike Blaszczak -- mikeblas@msn.com
Saturday, April 06, 1996

[Mini-digest: 3 responses]

> I can check Exit status of individual threads
> but keeping track of individual thread handles seems cumbersome.

Sometimes, if you write software, you have to do work.

> Do I have to release individual thread handles before

It's good practice to make sure the threads you've spawned have neatly 
terminated, just like it is good practice to make sure you've closed files and 
freed memory.

.B ekiM
TCHAR szSpringtime[] = _T("Cogito ergo wheelie.");

-----From: "VARughese GEOrge" 

i am afraid that you may have check te exist status (or signaled status) of 
each thread to see if they have terminated.. i had a little more complex 
problem in which the program spawns a number of worker threads to accomplish 
certain tasks and if the same task is requested while one is already running, 
the program should reschedule it until the running one is done. Since your 
requirement is only to termite the threads you may be able to live without 
keeping track of individual thread ids as well..

you may set an event signaling all threads to die when you want to exit the 
application and your worker threads may look at this event and die 
itself..(AfxEndThread)..alternatively for ui-threads use ::PostQuitMessage()

when you exit a process (ExitProcess) it shuts down all the threads of that 
process.. so you need not necessarily kill all the threads yourself if you 
don't want to..but the terminating process does not cause child process to be 
terminated!.

but why is that keeping track of threads cumbersome?


vargeo
http://ramco_web.ramco.com/vargeo.htm

i lost sight of the shore.... but where are the new oceans.??..

-----From: Marty Fried 

At 04:49 PM 4/5/96 -0500, CS wrote:
>Hi everyone,
>  I am using VC++ 4.0 to develop an SDI application for NT 3.51.  My
>  application spawns several threads and two background programs.  My
>question is : before exiting the application how can I check if my
>threads have terminated.  I can check Exit status of individual threads
>but keeping track of individual thread handles seems cumbersome.  Is
>there an effective way to do this task?  Also, do I have to release
>individual thread handles before the application terminates?

You can keep a list of thread handles in an array, and use this to 
WaitForMultipleObjects, then use the array to free the handles.  That's
probably the right way to do it.  Depending on what the threads are
doing, and what resources they may need to clean up, I believe you could
exit the program with threads active, and handles open, with no ill effects;
NT will clean up the remains.  At least, that's the way it seems to work,
but I personally think it's not good programming to do that.  Even if it's
safe now, programs get modified, and it may cause problems in the future.


________________________________
 Marty Fried (mfried@linex.com)
 Marin County, California






| Вернуться в корень Архива |