So the third function callback is nothing, but it is a function which the new thread will going to
execute.
Write Such type of functions have a fixed prototype and the prototype should be should be that that
these function must return void star.
And the argument to this function is also void star, right?
So you can see that the prototype of thread function callbacks is very generic, right?
So as soon as the child thread starts, the child thread invokes this function, right?
So in other words, this function will be executed in the context of a child thread, right?
Now our new thread must do some useful work.
Or maybe not useful, but a new thread must do some work.
So what are we going to do?
Is that I will simply extract the argument which was passed to our new thread.
So what was the argument which was passed?
The argument was nothing but the address of this input string.
Right?
So whatever memory you passed as the last argument to the P thread create function, the address of
that memory will be available as an argument to this thread function callback.
Right.
So you simply type cast it into the car star.
Right.
And now what I will going to do is that I will going to create an infinite loop and inside that loop
I will going to just print this string, right?
And I will going to use sleep one so that our new thread take a rest of one second.
Now in this Hello World program though, it is very simple and basic, but we will going to but we will
going to discuss several basic points regarding Multithreading.
Okay, so now let me compile this Hello World program.
The instruction to compile a multi multithreaded program is written at the top of the file.
So what you are going to do is that simply you can copy paste these lines, right?
And note that for a multithreaded program you need to link your executable with the P thread library.
So to specify the P thread library, you can simply write minus P thread.
Right?
And if you just press enter the hello world executable will be created and the expectation is that that
the main thread should get paused right here and the child thread must run in this infinite loop.
And every time the child thread must print this input string so you can see the same thing is happening
right?
So the child thread is running and it is printing the input string after every one second on the screen.
In other words, the child thread is doing its job, whereas the main thread is halt at the line number
77.
Right.
If we remove this line number 77 and if you execute this program again after compiling, of course,
then you will see that nothing happens, right?
Even before your child thread took a birth and start its life, your main thread had terminated and
if your main thread terminates, then all the child threads in the program gets terminated automatically.
Right?
So in other words, by removing this pause call from the function, we have hardly given any chance
to the child thread to take a birth and live its life.
I will show you shortly in this section that how you can allow your main thread to terminate while having
your child thread alive.
So now we will go into analyze this Hello World Multithreaded program from various aspects and understand
certain points regarding multithreading in the next couple of lecture videos.