dongse3348 2017-09-29 08:18
浏览 2027
已采纳

golang运行时:无法创建新的OS线程(已具有2049; errno = 12)

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条回答 默认 最新

  • dsqe46004 2017-09-29 08:27
    关注

    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, ")
    ")
        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.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了