0

Thread Join

While programming , many times we come across thread creation and thread management procedures. On such procedure related to thread management in a process is thread join. So what is thread join. Is it as intuitive as it sounds like joining two threads. Yes it is the procedure of joining two threads. But what does it actually means and what are the implications?

So thread join is used to attach one thread with another. Multiple  threads can be joined or attached to same thread. Basically this procedure is used to provide synchronization among multiple threads in multi-threading application.

Lets take the example of two threads to understand it more clearly.Lets say there are two threads, A and B. A is a parent thread and B is a child thread.  A has spawned B to perform some task concurrently while A continues to perform its original task. Now A has accomplished its task but B has not done yet. So in this scenario, A will exit after task completion and B will exit as well because its a child thread and child thread terminates on parent thread termination. So in this scenario, multi-threading has caused the unexpected early termination of an application prior to its task completion and this happened due to lack of synchronization between threads.  This sync will be achieved through thread join operation. When thread join is done by thread B on thread A, A will wait till the B completes its task and exits, thereafter A resumes its termination.

 

Share Button

Nidhi

Leave a Reply

Your email address will not be published.