Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go 我有一个关于发送者通道的影响的问题_Go - Fatal编程技术网

Go 我有一个关于发送者通道的影响的问题

Go 我有一个关于发送者通道的影响的问题,go,Go,如果我删除,我不清楚为什么func a1中的print语句不会打印任何内容,因为没有添加足够的框架代码(main函数、import语句等),使其在上可运行,并在您的问题中添加指向该语句的链接。我想我知道发生了什么,但如果没有更多的上下文,我无法确定。这是决定性的资源:打印仍有可能不会运行,因为在同步(通道读/写)之后发生的事情,直到下一个同步事件,都是并发的,这意味着没有顺序保证。 func a2(){ x := 3 result := make(chan int, 10)

如果我删除
,我不清楚为什么
func a1
中的print语句不会打印任何内容,因为没有添加足够的框架代码(
main
函数、import语句等),使其在上可运行,并在您的问题中添加指向该语句的链接。我想我知道发生了什么,但如果没有更多的上下文,我无法确定。这是决定性的资源:打印仍有可能不会运行,因为在同步(通道读/写)之后发生的事情,直到下一个同步事件,都是并发的,这意味着没有顺序保证。
func a2(){
    x := 3
    result := make(chan int, 10)
    input := make(chan int, 10)
    go a1(x, input, result)
    input <- 4
    <-result
}

func a1(x int, input <-chan int, result chan<- int){
    y := <-input
    fmt.Println("hello", y)
    result <- x
}

func a2(){
    x := 3
    result := make(chan int, 10)
    go a1(x, result)
    <-result
}

func a1(x int, result chan<- int){
    fmt.Println("hello")
    result <- x
}