0
0

More than 1 year has passed since last update.

fatal error: newproc: function arguments too large for new goroutine

Last updated at Posted at 2020-07-04

問題

fatal error: newproc: function arguments too large for new goroutine

goroutineを実行している部分でエラー

原因

起動時にスタックが大きいとエラーが発生するようで、
goルーチンで起動する関数の引数にでかい構造体が合っても同じことを言われます
(構造体の中にクソデカ配列があるなど)

type structure_t struct {
    kusodeka_array       [9999]int64
}

func (s structure_t) hogehoge () {}

func main() {
    structure := structure_t{}
    go structure.hogehoge()
}

解決策

引数がそのままスタックにコピーされないように
goルーチンを別の関数(下記の例では無名関数)で実行してから構造を呼び出す


go func() {
    structure.hogehoge()
}() 

もしくはhogehoge関数を定義している部分でレシーバをポインタレシーバにする

func (変数名 *structure_t) hogehoge () {}

恐らくエラーが起きている人は関数定義の部分で値渡し(値レシーバ)を設定しているので
どちらかというと後者の方法で直すのが良いと思います

そもそも値渡しだと関数で実行した結果が反映されないので
もし反映されないことを意図したものなら前者でも良いかも

感想

実行時にスタックが大きいの気にする割に
実行中にスタックでかくなっても気にしないのは笑えますね
(要するにgoルーチンは実行時(コンパイル時?)しかスタックの大きさを気にしてない)

参考

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0