<p>I am pretty new to Go so please forgive me if this question sounds dumb. I am going through the golang book and am in the section on concurrency. He example code is this</p>
<pre><code>package main
import "fmt"
func f(n int) {
for i := 0; i < 10; i++ {
fmt.Println(n, ":", i)
}
}
func main() {
go f(0)
var input string
fmt.Scanln(&input)
}
</code></pre>
<p>I am trying to understand how this works. So my question is does the fmt.Sclanln function take as input the output of the f(0) function to then feed back into that function?</p>
<hr/>**评论:**<br/><br/>NoEffex: <pre><p>The fmt.Scanln does nothing other than to stop the program from exiting before the f(0) function has completed by blocking until the user presses enter. If this wasn't there the program would immediatly exit before anything has happened because in Go the program terminate when the main function has completed. Since f(0) is in a seperate go routine it doesn't stop main from returning and will do so before f(0) has had a change to begin executing.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传