<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't count towards GOMAXPROCS.</p></pre>barsonme: <pre><p>chillin'.</p></pre>twek: <pre><p>well they're doing something, they have CPU time...</p></pre>TheMerovius: <pre><p>GC'ing is probably one of the things. And possibly IO, if you are doing any.</p></pre>twek: <pre><p>I'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'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't mean they exist. If they aren't needed, they aren't there.</p></pre>binaryblade: <pre><p>You arent using goroutines.....doesn't mean the stdlib isn't.</p></pre>twek: <pre><p>I guess thats my question, all I'm using is bufio.readers and maps, is there some bootstrapping stuff thats happening? I'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'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>"The GOMAXPROCS variable limits the number of operating system threads that can execute user-level Go code simultaneously."</p>
<p>I don't think it just fires up those threads if they aren't doing anything. It only limits the max number than can be executing at once.</p></pre>WellAdjustedOutlaw: <pre><p>I guess we're supposed to guess what your program is doing so we can then guess what packages it'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'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传