WEBVTT

00:04.960 --> 00:11.500
So guys covering the point number four that if main thread dies, then all other thread dies by default,

00:11.500 --> 00:13.270
but vice versa is not true.

00:13.270 --> 00:14.050
Right.

00:14.230 --> 00:20.650
So this is one corner case where main thread enjoys an extra privileges over other threads of your process.

00:20.950 --> 00:28.240
We have already seen that we inserted a pause function to prevent our main thread from dying out.

00:28.240 --> 00:28.900
Right.

00:28.930 --> 00:33.310
If you remove this pause function, then your entire process gets terminated quickly.

00:33.310 --> 00:33.910
Right.

00:33.940 --> 00:37.690
The child thread do not even get any chance to execute.

00:37.690 --> 00:38.350
Right.

00:38.470 --> 00:43.270
But now there is a way that you can actually allow your main thread to die out.

00:43.300 --> 00:48.820
Keeping all the child threads that is created by your program to stay alive.

00:48.970 --> 00:54.970
You can do so by simply terminating the main thread using p thread exit API.

00:55.540 --> 00:56.410
Right.

00:57.460 --> 01:03.730
Now if you run this program, your main thread will get terminated immediately, but your child thread

01:03.730 --> 01:08.720
will successfully take a birth and execute and it will continue to execute.

01:08.720 --> 01:09.410
Right.

01:09.650 --> 01:16.310
So if you allow the normal termination of your main thread by simply returning return zero from the

01:16.310 --> 01:20.100
main function, then of course your entire process will get terminated.

01:20.120 --> 01:26.360
But if you terminate your main thread using p thread underscore exit API, then all the child threads

01:26.360 --> 01:29.900
would continue to stay alive and continue to execute.

01:29.900 --> 01:30.590
Right.

01:30.800 --> 01:36.470
So you can actually make all these minor code changes in your Hello world example and see that what

01:36.470 --> 01:38.990
is being said is actually correct and true.

01:39.590 --> 01:42.950
But what happens if any child thread terminates?

01:42.980 --> 01:48.860
If any child thread terminates, then really there is no impact on any other thread that your process

01:48.860 --> 01:49.580
has.

01:49.610 --> 01:54.320
When there is a termination of the child thread, only that child thread is terminated.

01:54.320 --> 01:55.040
Right.

01:55.700 --> 02:02.090
So whether you terminate the child thread by cancellation or by p thread exit or by returning from the

02:02.090 --> 02:07.280
thread function, it really don't matter when the child thread terminates, it terminates the child

02:07.310 --> 02:08.240
thread only.
