Hello and welcome to the go like programming languages course in this session, we want to talk about
the others concurrency concept.
How to create a go routine, you can create your own goal routine simply by using Google Keyboard as
a perfect seeing to the function or method car go land uses a special keyboard go for starting a go
routine to a start one.
Just edit go pure or before a function or method.
Call that function.
Our method will now be executed in the goal routine.
Let's understand the difference between normal running IT function and running it function as a goal
routine.
Normal running a function in the normal running of the function for the above scenario.
First statement one will be executed, then start function will be called.
And once this start function finishes, then the statement two will be executed once in running and
function as a goal routine for the above scenario.
First, a statement one will be executed, then functions start will be called as a goal routine, which
will execute asynchronously.
A statement to will be executed immediately.
It will not wait for a soft function to complete their start.
Function will be executed concurrently as a goal routine, while the rest of the program continues its
execution.
So basically, when calling a function as Security Council will return immediately, the execution will
continue from next long, while the go routine will be executed concurrently in the background.
Also note that any return value from the gore team will be ignored.
Now, let's go to the escort program to understand the above point.
First, define the function named display font display
and create a statement like print a message FP in go routine.
Now go to the main function and call the created function
go display.
And now some statements after invoking function, for the example, if the panel.
And if the good goodbye.
OK.
Reformat the call, said the project and execute the program go round.
I guess must mean that go.
Now we can see the output in edible program.
We used to go keyboard before a function called to start a good routine go display.
This syntax for calling a function will start a go routine, which will run the display function.
The program first print Hello, noticed that the line in which we print hello is after the goal or Tunisia
started.
But there is a problem.
It only displays the result of the normal function that does not display the result of core routine,
because when the new gore team executed, the gore routine can't return immediately.
The control does not wait for gore routine to complete their execution, just like normal functions.
They always move forward to the next line after the gore team call and ignores the value returned by
the gore team.
So to execute a gore routine properly.
We made some changes in our program and we then put a timeout.
The timeout is there so that the gore team gets its catch will be for the main gore team has to exist.
So after print hello message, the at a time out, a statement saw we write
Time doth sleep.
And sits one asterisk time dot second.
Reformat the code, save the project and execute the program again.
Now we can see the output halo in goal routine and goodbye.
Now we could define the goal routine and execute it, see gold in function invoked and output display.
In order not to prolong the time of decision, we will finish it and we will continue the content in
the next session.
Goodbye.