Hello and welcome to the goal and programming language course in this session, we want to talk about
the authors concurrency concept.
Beaufort Channel and Go Lake.
Channels can be defined as a pipes using which go routines communicate similar to water flows from one
end to another in the pipe.
Data can be sent from one end and received from the other and using channels.
By default, channels are on buffer, which states that they will only accept sense if there is a corresponding
greasy which are ready to receive the sand value.
Both our channels allow us to accept a limited number of values without a corresponding receiver for
those values.
It is possible to create a channel with a buffer buffer channel or are blocked only when the buffer
is full.
Similarly, switching from a buffer channel are blocked only when the buffer will be empty.
Buffer channels can be created by passing an additional capacity parameter to the make function, which
specifies the size of the buffer.
Now you can see the same tax chan defined channel time and capacity as specifies the size of the buffer
here.
Capacity is about syntax should be greater than zero for the channel to have a buffer.
The capacity for an unbar for channel is 0y defined enhance its army the capacity parameter.
Now, let's go to this school with program to illustrate on Buffer and Beaufort, China.
First, define the channel by make function, for example, define a variable like search calling equals
make and channel by the time S3.
Sin Daytimes is trying to create a channel switch channel operator forcing and set a variable like go
now, receive send data off the channel and put into a string variable.
For example, define a variable like age column equals channel operator search.
So print message, variable value FP.
Message.
Reformat the quote, safe deposit and execute the courier go from the bank is less me, that's cool.
OK, now we can see the output fatal error of all go routines are athlete dead luck.
In this case, this code will produce a dead lunch because it tries to send and receive data from channel
servers within the same goal routine, which is made since channel operations are blocking the goal
routine.
The main goal routine stops at S.H. forever since it's blocked, and it would never reach the line.
Message column equals channel operator search.
The simple workaround for this problem is to use a buffer chairman.
The buffer channel will not be go with him unless it is put, so be bound to defined buffer channel
by the make function and set buffer capacity.
Now go to main function and change.
Make function to buffer channel for the example, at one end buffer capacity as a second argument.
Come on and sit one, so execute program again.
Now we can see the output go like in this example, we make the Beaufort channel the size equal to one.
The channel can hold one data and will not block main function so that we can proceed to the line.
Mrs. Carlin equals channel operator.
However, if we try to spend more than one data through this channel before we receive data from it,
that large will happen again.
Because the size of the disparate channel is only one exam in this case, and changes send data to more
than 40 example at another.
Send data in order not to prolong the time of decision.
We will finish it and we will continue the content in the next session.
Goodbye.