Skip to content

Commit

Permalink
Merge pull request #51 from qmuntal/sync
Browse files Browse the repository at this point in the history
Fix race condition on ParallelInit
  • Loading branch information
MaxHalford authored Feb 12, 2021
2 parents 90770d5 + a965058 commit 3581619
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion individuals.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ func newIndividuals(n uint, parallel bool, newGenome func(rng *rand.Rand) Genome
for a := uint(0); a < n; a += chunkSize {
a := a // https://golang.org/doc/faq#closures_and_goroutines
var b = minUint(a+chunkSize, n)
seed := rng.Int63()
g.Go(func() error {
indRNG := rand.New(rand.NewSource(rng.Int63()))
indRNG := rand.New(rand.NewSource(seed))
for i := a; i < b; i++ {
indis[i] = NewIndividual(newGenome(indRNG), indRNG)
}
Expand Down

0 comments on commit 3581619

Please sign in to comment.