Just question on concurrency in Go

agolangf · · 347 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<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 &#34;fmt&#34; func f(n int) { for i := 0; i &lt; 10; i++ { fmt.Println(n, &#34;:&#34;, i) } } func main() { go f(0) var input string fmt.Scanln(&amp;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&#39;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&#39;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

347 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传