2,190
社区成员
发帖
与我相关
我的任务
分享
func test1_a() {
c := make(chan bool)
go func() {
fmt.Println("done")
<-c
}()
c <- true
}
func test1_b() {
c := make(chan bool)
go func() {
fmt.Println("done")
c <- true
}()
<-c
}
func test1_2a() {
c := make(chan bool,1)
go func() {
fmt.Println("done")
<-c
}()
c <- true
}
func test1_2b() {
c := make(chan bool,1)
go func() {
fmt.Println("done")
c <- true
}()
<-c
}
func test2_a() {
c := make(chan bool)
i := 0
var condition int = 3
go func() {
for {
if i++; i < condition {
//Do Something
c <- true
} else {
//Do Something else
}
}
}()
for v := range c {
fmt.Println(v)
}
}
func test2_b() {
c := make(chan bool, 5)
i := 0
var condition int = 3
go func() {
for {
if i++; i < condition {
c <- true
} else {
//Do Something
}
}
}()
for v := range c {
fmt.Println(v)
}
}
func test2_2a() {
runtime.GOMAXPROCS(2)
test2_a()
}
func test2_2b() {
runtime.GOMAXPROCS(2)
test2_b()
}