Skip to content

Instantly share code, notes, and snippets.

@scbizu
Created May 30, 2016 10:40
Show Gist options
  • Save scbizu/a061330156666a091d9c2ee31b2bfe21 to your computer and use it in GitHub Desktop.
Save scbizu/a061330156666a091d9c2ee31b2bfe21 to your computer and use it in GitHub Desktop.
an example for how to make mutil-thread code with Golang
package main
import "fmt"
/*
*Question:
*使用Channel堵塞主线程 等待Gor GO完
*/
var chan1 chan int = make(chan int)
func test() {
fmt.Println("Main Start")
//lock main thread to wait for the GoR1
<-chan1
}
func main() {
go func() {
fmt.Println("GoR1 was finished")
//give a singal to main thread ,if not do this ,main will be deadlocked(keep waiting for the data flow into the chan)
chan1 <- 1
}()
test()
fmt.Println("Main was finished")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment