pond icon indicating copy to clipboard operation
pond copied to clipboard

run stop panic

Open liusl104 opened this issue 2 years ago • 0 comments

test demo : package main

import ( "fmt" "github.com/alitto/pond" "time" )

func testPool(i int, p *pond.WorkerPool) { if i == 8 { var stop string // fmt.Printf("stop -- %d : ", i) // fmt.Scanln(&stop) stop = "yes" if stop == "yes" { fmt.Println("stop ok") p.Stop() return }

}
fmt.Printf("run %d \n", i)
time.Sleep(time.Duration(i) * time.Second)

} func main() { // Create a buffered (non-blocking) pool that can scale up to 100 workers // and has a buffer capacity of 1000 tasks pool := pond.New(5, 1000, pond.MinWorkers(5))

// Submit 1000 tasks
for i := 1; i < 1000; i++ {
	n := i
	pool.Submit(func() {
		testPool(n, pool)

	})
}
// pool.RunningWorkers()
// Stop the pool and wait for all submitted tasks to complete
fmt.Println("wait all task done ...")
pool.StopAndWait()

} package main

import ( "fmt" "github.com/alitto/pond" "time" )

func testPool(i int, p *pond.WorkerPool) { if i == 8 { var stop string // fmt.Printf("stop -- %d : ", i) // fmt.Scanln(&stop) stop = "yes" if stop == "yes" { fmt.Println("stop ok") p.Stop() return }

}
fmt.Printf("run %d \n", i)
time.Sleep(time.Duration(i) * time.Second)

} func main() { // Create a buffered (non-blocking) pool that can scale up to 100 workers // and has a buffer capacity of 1000 tasks pool := pond.New(5, 1000, pond.MinWorkers(5))

// Submit 1000 tasks
for i := 1; i < 1000; i++ {
	n := i
	pool.Submit(func() {
		testPool(n, pool)

	})
}
// pool.RunningWorkers()
// Stop the pool and wait for all submitted tasks to complete
fmt.Println("wait all task done ...")
pool.StopAndWait()

} output : run 1 run 3 run 2 wait all task done ... run 4 run 5 run 6 run 7 stop ok run 9 run 10 fatal error: all goroutines are asleep - deadlock!

liusl104 avatar Oct 07 '23 08:10 liusl104