golang 运行时:无法创建新的操作系统线程(已经有 2049;errno=12)
时间:2023-03-20
浏览:302
作者:佚名
一分耕耘,一分收获!既然都打开这篇《golang 运行时:无法创建新的操作系统线程(已经有 2049;errno=12)》,就坚持看下去,学下去吧!本文主要会给大家讲到golang等等知识点,如果大家对本文有好的建议或者看到有不足之处,非常欢迎大家积极提出!在后续文章我会继续更新Golang相关的内容,希望对大家都有所帮助!
问题内容
我在 MacO 上创建了很多 goroutine,程序执行时出现错误。
goRoutineId = 3710, i = 3683, len(chan) = 2049 runtime: failed to create new OS thread (have 2049 already; errno=12) fatal error: runtime.newosproc
所以我想知道“无法创建新的OS线程”是什么意思,是操作系统的限制,只是golang没有能力创建更多的goroutine吗?感谢你们对我的帮助。
正确答案
这是操作系统的限制。我假设您使用的是linux。
根据go的来源,它正在调用clone系统调用
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")
}
从[克隆(2)的手册页中](http://man7.org/linux/man-
pages/man2/clone.2.html#RETURN_VALUE),当
时errno=12,错误原因是[内存不足](https://github.com/torvalds/linux/blob/master/include/uapi/asm-
generic/errno-base.h)
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.
好了,本文到此结束,带大家了解了《golang 运行时:无法创建新的操作系统线程(已经有 2049;errno=12)》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.30
11.30
11.29
11.29
11.29
热门专题
