Closed hbh112233abc closed 1 year ago
以下这平平无奇的代码,怎么就会发生崩溃呢
package main import ( "fmt" "math/rand" "sync" "time" "github.com/devchat-ai/gopool" ) func main() { var m sync.Map pool := gopool.NewGoPool( 20, gopool.WithMinWorkers(3), ) defer pool.Release() var i = 0 for { i += 1 if _, ok := m.Load(i); !ok { pool.AddTask(func() (interface{}, error) { m.Store(i, 1) task(i) m.Delete(i) return nil, nil }) } if i > 20 { break } } pool.Wait() } func task(t int) error { i := rand.Intn(20) time.Sleep(time.Second * time.Duration(i)) fmt.Printf("> %d -- %d \n", t, i) return nil }
@hbh112233abc 抱歉,上周有些事情忙着,没腾出手,到现在才细看你提的这个 issue;我已经修复了这个问题,麻烦更新到 0.6.2 版本再试试。
以下这平平无奇的代码,怎么就会发生崩溃呢