Skip to content

Commit

Permalink
fix: do initParallelRunner() only once no matter how many chains are …
Browse files Browse the repository at this point in the history
…created by NewBlockChain()
  • Loading branch information
andyzhang2023 committed Oct 25, 2024
1 parent 938ac30 commit 8fbb333
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions core/parallel_state_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ import (
)

var runner chan func()
var runnerOnce sync.Once

func initParallelRunner(targetNum int) {
if targetNum == 0 {
targetNum = runtime.GOMAXPROCS(0)
}
runner = make(chan func(), targetNum)
for i := 0; i < targetNum; i++ {
go func() {
for f := range runner {
f()
}
}()
}
runnerOnce.Do(func() {
if targetNum == 0 {
targetNum = runtime.GOMAXPROCS(0)
}
runner = make(chan func(), targetNum)
for i := 0; i < targetNum; i++ {
go func() {
for f := range runner {
f()
}
}()
}
})
}

func ParallelNum() int {
Expand Down

0 comments on commit 8fbb333

Please sign in to comment.