What happens to threads in a class?
What happens if one calls a function in a class that starts a thread which then completes? I assume the thread is gone. Now next time one wants to run the function again, the thread has to be re-created. Will this cause some type of problem or is there something one should do upon thread termination like CloseHandle() or be sure that the thread has (indeed) run to completion?
Re: What happens to threads in a class?
Quote:
Originally posted by Gyannea
What happens if one calls a function in a class that starts a thread which then completes? I assume the thread is gone.
Correct...
Quote:
Originally posted by Gyannea
Now next time one wants to run the function again, the thread has to be re-created.
Yes...
Quote:
Originally posted by Gyannea
Will this cause some type of problem or is there something one should do upon thread termination like CloseHandle() or be sure that the thread has (indeed) run to completion?
Well...it depends on several things. Whether you have to close a handle actually depends on the function you used to create the thread. Take a look at this FAQ for further information.
For the second part...you do not need to wait until the first created thread has terminated. It basically depends on what you are trying to accomplish....but usually you use threads to do things simultanously...however, you need to make sure that (depending on the method used to create the thread) you store each thread handle so that every handle gets closed by a call to 'CloseHandle()'...