ch := make(chan bool) means you want to have an unbufferred channel. Send 
and Receive are block operations. In other words, send will block unless 
there is a receive operation, which is the case in your code. All calls to 
increment are blocked at ch <- true.

When you change it to ch := make(chan bool, 1), you create a bufferred 
chanel, send does not block and program moves on to empty the channel at 
<-ch.

Imp thing to note here is that when you exceed the send operations by 
channel capacity, it starts acting like an unbufferred channel.

On Friday, May 4, 2018 at 6:51:49 PM UTC+5:30, k1at...@gmail.com wrote:
>
> Hi
>
> i dont' understn what is the difference between :
>
> ch := make(chan bool,1)       vs.     ch := make(chan bool)
>
> this sample works well :
>
> package main
>
> import (
> "fmt"
> "sync"
> )
>
> var x = 0
>
> func increment(wg *sync.WaitGroup, ch chan bool) {
> ch <- true
> x = x + 1
> <-ch
> wg.Done()
> }
> func main() {
> var w sync.WaitGroup
> ch := make(chan bool,1)                       <------it is OK , but if i 
> change to  ch := make(chan bool) - it doesn't work
> for i := 0; i < 1000; i++ {
> w.Add(1)
> go increment(&w, ch)
> }
> w.Wait()
> fmt.Println("final value of x", x)
> }
>
> Thank you in advance
>

-- 
*::DISCLAIMER::

----------------------------------------------------------------------------------------------------------------------------------------------------


The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
<http://redbus.in/>com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::

----------------------------------------------------------------------------------------------------------------------------------------------------


The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
<http://redbus.in/>com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to