golang runtime implement libc pthread_create, mutex, malloc. it doesn't use libc API, use OS syscall instead.
- malloc
- golang memory allocator:
src/runtime/malloc.go
- golang memory allocator os specific:
src/runtime/mem_bsd.go
sysAlloc()
usemmap()
syscall instead of libcmalloc()
- pthread_create
- Goroutine scheduler:
src/runtime/proc.go
- G is goroutine, M is worker thread, or machine
- coroutine on thread pool?
newm()
usenewosproc()
: https://github.com/golang/go/blob/release-branch.go1.7/src/runtime/proc.go#L1572
- mutex lock
- golang mutex lock:
src/runtime/lock_futex.go
lock(l *mutex)
usefutexsleep()
: https://github.com/golang/go/blob/release-branch.go1.7/src/runtime/lock_futex.go#L101
- syscall wrapper:
src/runtime/sys_freebsd_amd64.s
- golang os specific api:
src/runtime/os_freebsd.go
- spawn thread:
newosproc():
https://github.com/golang/go/blob/release-branch.go1.7/src/runtime/os_freebsd.go#L104 - mutex lock:
futexsleep()/futexwakeup()
- spawn thread: