简体   繁体   English

为什么golang选择了系统调用而不是libc

[英]why golang chose syscall rather than libc

Go wraps all syscall-s in package syscall, just like what libc does if I understand them right. 在包syscall中包装所有syscall-s,就像libc所做的那样,如果我理解它们的话。

I've researched a few languages, 我研究了几种语言,

  • Haskell, using libc in compiler and the libraries normally use it too, although there is a few libraries wrapping syscall for users. Haskell,在编译器中使用libc,并且库通常也使用它,尽管有一些库为用户包装syscall。

  • Java and almost all JVM languages choosing libc. Java和几乎所有选择libc的JVM语言。

No need mention script languages, such as lua, ruby or python, they need portable, so they need libc as an implementation of POSIX. 不需要提及脚本语言,例如lua,ruby或python,它们需要可移植,因此它们需要libc作为POSIX的实现。

I didn't use rust recently, but there are some people just said rust using libc too. 我最近没有使用锈,但也有一些人说使用libc也生锈了。

So, why golang decided to implement a syscall package at first. 那么,golang为什么决定首先实现一个系统调用包。 It's not portable, cost more people to port to each kernel, even each major version of the same kernel. 它不可移植,移植到每个内核,甚至同一内核的每个主要版本都需要更多人。

Because Go manages its processes in goroutines managed by the Go Runtime which is written in C and statically linked to the compiled user code during the linking phase. 因为Go管理由Go Runtime管理的goroutine中的进程,它是用C语言编写的,并且在链接阶段静态链接到编译的用户代码。 Since go manages its syscall with its own runtime not directly in the OS, that is why it implemented its own syscall package. 由于go使用自己的运行时不直接在OS中管理其系统调用,因此它实现了自己的syscall包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM