Created
May 30, 2016 10:40
-
-
Save scbizu/a061330156666a091d9c2ee31b2bfe21 to your computer and use it in GitHub Desktop.
an example for how to make mutil-thread code with Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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