Hello and welcome to the Golang programming language course in this session, we want to talk about
the others concurrency concept.
Multiple goal routines.
A go routine is a function or method which executes independently and Simon Astley in connection with
any other goal routines present in your program or in other words, every concurrently executing activity
in language's is known as a go routine and go language.
You are allowed to create multiple goal routines in a single program.
Now, let's go to the school for a to illustrate how to start multiple goal routines.
First, define a function like name for goal routine, one that includes an array of printing names,
so define font name.
Create this string array variable that contains four values.
For example, array one column equals four by the time the string and initialize it by values like Clean
Jessica.
Julia
and Tom now define a for loop, for a a slip and preen the venues off area for
I equals zero.
I less than four and I + + +, said the statement time dots lead and set a value like a hundred and
fifty multiplication time milliseconds.
And print each value of a f f per cent less brackets less and and any one index I.
OK, now let's go to define a function like IED for routine to that includes an array of printing IED.
So define another function, like I'd
define an integer at a variable that contains four value at a two column he calls for by the tight end
and initialize to it by the values like three hundred three hundred and one to the handwritten to three
hundred and three.
Now define a follow for set a time slip and print the values of at a two four I equals zero I less than
four and set the timeously time.
That's clear.
For example, five hundred multiplication time, milliseconds time, that's merely sec and display each
value off array.
If if a person the bank slips in and set I to index my.
Now create main function to invoke 2go routines functions.
FAJ me
first print a message like if the
main girl routine is start
now calling name function as go routine, want full name function?
And calling it function as go routine to go I.D.
now set the time asleep and print a message for end of process, time to sleep
set, for example, five hundred multiplication times dot milliseconds
and set the message like FP made so routine and.
In the above example, you have to go through items other than mail or routine eye in name and I.D.
Here are name prints to name and I.D. prints to Iris.
Now we go to run the, you know, go round dots back.
Excuse me that go.
Now we can see the output when we were on this program.
First, the main goal routine routines start and print main goal routine is start here.
The main goal routine is like a pattern, and other goal routines are its children.
So first may go routine runs.
After that, those other goal routines is start.
And if the main goal routine training is, the other goal routines are also terminated.
So after the main goal routine name and I the goal routines is stop, they're working concurrently in
order not to prolong the time of decision.
We will finish, then we will continue the content in the next session until next session.
Goodbye.