This is the situation. I have an application that creates 2 child Threads. When I call Join method for ChildThread1, MainThread waiting for this join operation. It is freezing. But this is not the point. It is expected.
The point is how ChildThread2 affected in this operation. Does It wait for this operation or run normally?
Thanks.
This is the situation. I have an application that creates 2 child Threads. When
Share
ChildThread2 is not affected.
Now, if it’s a background thread, and if the
Joinis the last thing thatMaindoes before exiting, then that will killChildThread2, but this has nothing to do with theJoinitself, but with the fact that once all non-background threads have finished, the application shuts down, killing all background threads.If it isn’t a background thread, then this doesn’t apply – either the main thread exits (after
ChildThread1since theJoinmeans it waited on it), and then the second spawned thread finishes, or else the second thread spawned thread was already finished, and when they’re all finished the application ends.Note that if you try to
Joina thread that is already finished, the call toJoinreturns immediately. Therefore if you want a thread to wait on two or more threads, and can’t predict their order, it’s perfectly okay to wait on one and then the other.