<p>Go 1.5 has been rewritten completely in Go language itself. However, let's say the maintainers came up with a faster and more efficient way to implement one of its core features, e.g. goroutines. There is no way to implement goroutines in Go that I am aware of. It is a feature in the language spec.</p>
<p>Am I wrong? How would the developers improve the performance of something like goroutines without access to its low level C code?</p>
<hr/>**评论:**<br/><br/>tuxychandru: <pre><p>The goroutine scheduler is part of the runtime and it is written in Go.</p></pre>bpq: <pre><p>Okay, where is the source for the goroutine scheduler or the go statement?</p>
<p>I think I would understand a bit more if I see how the code works.</p></pre>YEPHENAS: <pre><p><a href="https://github.com/golang/go/blob/master/src/runtime/proc1.go#L2170">https://github.com/golang/go/blob/master/src/runtime/proc1.go#L2170</a></p>
<p>In general:</p>
<ul>
<li>Scheduler: <a href="https://github.com/golang/go/blob/master/src/runtime/proc1.go">https://github.com/golang/go/blob/master/src/runtime/proc1.go</a></li>
<li>Memory allocator: <a href="https://github.com/golang/go/blob/master/src/runtime/malloc.go">https://github.com/golang/go/blob/master/src/runtime/malloc.go</a></li>
<li>Garbage collector: <a href="https://github.com/golang/go/blob/master/src/runtime/mgc.go">https://github.com/golang/go/blob/master/src/runtime/mgc.go</a></li>
</ul></pre>bpq: <pre><p>Thank you.</p>
<p>That is interesting. Now another question; are there any low-level go functions/packages that are not exposed in the language specification? For example, a low-level function like C's malloc in Go? If yes, is it possible to use those in normal packages?</p></pre>YEPHENAS: <pre><p>You probably mean "in the standard library", because the language
specification is this document: <a href="https://golang.org/ref/spec">https://golang.org/ref/spec</a>
It does not talk about the packages and functions of the standard library.</p>
<p>The lowest level of functions are system calls. They are calls to the
operating system kernel. The system calls needed by Go are exported
in the syscall package: <a href="http://golang.org/pkg/syscall/">http://golang.org/pkg/syscall/</a></p>
<p>However, most of the runtime functions are not exported, only a few:
<a href="https://golang.org/pkg/runtime/">https://golang.org/pkg/runtime/</a></p></pre>bpq: <pre><p>Thank you again.</p>
<p>I didn't know about system calls, and the syscall package. So, Go uses syscall for low-level functions, and they seem to be written in Assembly and Go. And this is why there is no need for C anymore.</p></pre>hobbified: <pre><p>Syscalls are provided by the OS kernel. They're written in whatever, they're not part of the go runtime. They're the interface between the OS and the applications that run on it. And they're not really relevant to why "there's no need for C anymore" — the C code used syscalls in the same places for the same reasons — to invoke OS services.</p>
<p>The point is simply that Go with a few snippets of asm can do exactly what C with a few snippets of asm can, so the two are interchangeable.</p></pre>davecheney: <pre><p>No, they are not exported by the <code>runtime</code> package.</p></pre>DannyDeck: <pre><p>Goroutines are a feature of the Go runtime. The Go runtime is (was?) written in Go, C, and asm.</p>
<p>This gives a good explanation of the runtime that I think will answer your question: <a href="http://www.quora.com/How-does-the-Go-runtime-work">http://www.quora.com/How-does-the-Go-runtime-work</a></p></pre>4ad: <pre><p>The runtime is <del>not</del> <strong>now</strong> written in Go and assembly, there is no C anymore.</p></pre>natefinch: <pre><p>s/not/now/ I think you mean</p></pre>4ad: <pre><p>Thanks.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传