golang runtime: failed to create new OS thread (have 2049 already; errno=12)

大兔子大兔子 提交于 2019-12-25 08:48:37

问题


I created lots of goroutines on MacOs, and there was an error emitted when program executing.

goRoutineId = 3710, i = 3683, len(chan) = 2049
runtime: failed to create new OS thread (have 2049 already; errno=12)
fatal error: runtime.newosproc

So I wonder what the "failed to create new OS thread" means, is that an operating system limitation, of just golang has no ability to create more goroutine? Thank you for helping me.


回答1:


It's OS's limitation. I would assume you are using linux.

According to the source of go, it is calling clone system call

ret := clone(cloneFlags, stk, unsafe.Pointer(mp), unsafe.Pointer(mp.g0), unsafe.Pointer(funcPC(mstart)))
sigprocmask(_SIG_SETMASK, &oset, nil)

if ret < 0 {
    print("runtime: failed to create new OS thread (have ", mcount(), " already; errno=", -ret, ")\n")
    if ret == -_EAGAIN {
        println("runtime: may need to increase max user processes (ulimit -u)")
    }
    throw("newosproc")
}

from the manpage of clone(2), when the errno=12, the error reason is out of memory

ENOMEM Cannot allocate sufficient memory to allocate a task structure
              for the child, or to copy those parts of the caller's context
              that need to be copied.


来源:https://stackoverflow.com/questions/46484627/golang-runtime-failed-to-create-new-os-thread-have-2049-already-errno-12

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!