Hello and welcome to the godowns programming language course in this session, we want to talk about
the others concurrency concept.
Send and receive data from it, Shannon.
Ingo Language Channel works with two principal operations one is sending and another one is receiving
both the operations, collectively known as communication and the direction of channel operator, indicates
whether the data is received or sent in the channel.
The sand and receive Operation Block until another side is not ready.
By default, it allows go routine to synchronize with each other without explicit locks or conditioned
variables sent operation.
The Senate operation is used to send data from one go routine for another go routine with the help of
a chairman.
Values like Ain't Float 64 and Bull can safe and easy to Santeria channel because they are copied,
so there is no risk of accidental concurrent access of the same value.
Similarly, strings are also safe to transfer because they are immutable both for sending pointers or
a reference like a slice map and etc. through a channel are not safe because the value of pointer over
things may change by sending gore rooting or by the receiving go rating at the same time.
The result is unpredicted.
So when you use pointers or references in the channel, you must make sure that you can only access
by one go routine at a time.
Now you can see the syntax there.
Bauer's statement indicates that the data means element sent to the channel with the help of the channel
operator
receive operation.
The receive operation is used to receive the data sent by the ST operator.
Now you can see the syntax.
The Obama's statement indicates that the element receives data from the channel.
If the result of the received a statement is not going to use is also valid, the statement you can
answer right or receive a statement as below.
Receive Operator Channel name.
Now, let's go to the school program to illustrate, send and receive operation.
First, define a function that sent an integer value to a channel.
In sum, it by another value.
So define fine sand set a variable like C-H Chan y, the Typekit
C-H send operator and for example, 50, and we defined a function that received the channel and some
channel value by another value.
For example, we defined find.
Receive.
Sea urchin pointed at tie ins
and preen total of 200 value by channel value, so be right.
If the
200 plus receive operator, see each,
now go to main function and call these two go routines.
First, write the message as being of main function words if the taught main function.
And now creating a channel by make function, for example, defining variable voices, calling equals
and calling make function.
And said Chan, and end time now sending money to channel by inbox and function, go send and pass CHF
argument.
And receiving value of channel by increasing function, go receive.
And posterior argument sit as the prime time got its lead
time darts for second multiplication in hundreds and now write a message as end of main function watch
FP
and of the named Punch P format the court, save the person, execute the program.
Go run that back.
Is this mean that go now we can see the output in our program.
We created the channel named C-H, whose data time is eons, which means that it can only transport
data off type.
Integer function, send and receive are started as a go routine.
We are sending data to the channel.
Searching single routine and receiving data from C is in the received go routine in order not to prolong
the time of decision.
We will finish it and we will continue the content in the next session.
Goodbye.