What do the other threads do in a go program w.o goroutines?

agolangf · · 442 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello, when you create a simple golang program I know it launches GOMAXPROC threads, my question is, if you never launch a goroutine, what are they doing?</p> <hr/>**评论:**<br/><br/>bradfitz: <pre><p>You have have GOMAXPROCS running your code, and nearly unlimited (well, 10,000 max by default) in system calls, waiting or doing work in the kernel. The ones in system calls don&#39;t count towards GOMAXPROCS.</p></pre>barsonme: <pre><p>chillin&#39;.</p></pre>twek: <pre><p>well they&#39;re doing something, they have CPU time...</p></pre>TheMerovius: <pre><p>GC&#39;ing is probably one of the things. And possibly IO, if you are doing any.</p></pre>twek: <pre><p>I&#39;m doing a ton of bufio.writer operations are those done on separate goroutines?</p></pre>Akkifokkusu: <pre><p>Where are those writes going?</p></pre>twek: <pre><p>files on disk</p></pre>TheMerovius: <pre><p>In that case: Possibly, yes. AFAIK go doesn&#39;t use asynchronous io for file reads/writes, so it might need to create threads for the writes.</p></pre>TheMerovius: <pre><p>Maybe. But also, GC.</p></pre>itsmontoya: <pre><p>Just because the max is set, doesn&#39;t mean they exist. If they aren&#39;t needed, they aren&#39;t there.</p></pre>binaryblade: <pre><p>You arent using goroutines.....doesn&#39;t mean the stdlib isn&#39;t.</p></pre>twek: <pre><p>I guess thats my question, all I&#39;m using is bufio.readers and maps, is there some bootstrapping stuff thats happening? I&#39;m just trying to understand how golang works internally.</p></pre>binaryblade: <pre><p>it is open source, you can read all the code in the stdlib. In fact I believe that is recommended so that you can become acquainted with idiomatic go.</p></pre>barsonme: <pre><p>it&#39;s one of the reasons they bootstrapped the compiler to go---so us plebs could read it and (hopefully) understand and help with it :)</p></pre>djherbis: <pre><p>from: <a href="https://golang.org/pkg/runtime">https://golang.org/pkg/runtime</a>,</p> <p>&#34;The GOMAXPROCS variable limits the number of operating system threads that can execute user-level Go code simultaneously.&#34;</p> <p>I don&#39;t think it just fires up those threads if they aren&#39;t doing anything. It only limits the max number than can be executing at once.</p></pre>WellAdjustedOutlaw: <pre><p>I guess we&#39;re supposed to guess what your program is doing so we can then guess what packages it&#39;s using, so we can guess which components might be creating goroutines so we can guess which of those then create OS threads?</p></pre>twek: <pre><p>I mentioned in another comment. Maps and bufio.writers. It&#39;s a very simple program. </p></pre>jmatosp: <pre><p>If you are running a HTTP server type app, you are using goroutines...</p> <p>Each request will spawn a new goroutine and potentially a thread </p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

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