-
March 30th, 2009, 06:14 PM
#1
basic thread question
Hi
I have a question about when thread terminates.
Say I have the following
Code:
void foo()
{
Thread(/* all the params */); // e.g. CreateThread()
}
int main()
{
foo();
}
My questions are;
Q1. If I dont explicitly call ExitThread(), when does the process created by Thread() terminates?
Q2. Do all the threads created inside main() end when the program exits
without having called the functions that end the threads?
Thanks alot for the help~
-
April 1st, 2009, 01:58 AM
#2
Re: basic thread question
Answer to Q1: All Thread must has a method run(). When the method run() finished, the thread ended.
Answer to Q2: Other threads will not be terminated automatically when the main() method finishes. But I think all threads will be terminated when you call System.exit().
-
April 1st, 2009, 10:22 AM
#3
Re: basic thread question
Q1: Windows/Posix - Consider the thread "no longer running" when you return from the thread function.
Q2: Windows(MSCRT)/Posix - Returning from main() is the same as calling exit() - which kills all threads and the process.
gg
-
April 2nd, 2009, 05:29 AM
#4
Re: basic thread question
thank you Syoleen and Codeplug!
That makes it more clear.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|