From d5ada57f6d9cef76986299a1a496349bff7be64e Mon Sep 17 00:00:00 2001 From: Cheng Ding <73172305+IrisesD@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:32:30 +0800 Subject: [PATCH] update to fix data race --- training/model.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/training/model.go b/training/model.go index aee09de..cef6885 100644 --- a/training/model.go +++ b/training/model.go @@ -1,6 +1,9 @@ package training -import "math/rand" +import ( + "math/rand" + "sync" +) // Example is an input-target pair type Example struct { @@ -8,14 +11,18 @@ type Example struct { Response []float64 } +var mu sync.Mutex + // Examples is a set of input-output pairs type Examples []Example // Shuffle shuffles slice in-place func (e Examples) Shuffle() { for i := range e { + mu.Lock() j := rand.Intn(i + 1) e[i], e[j] = e[j], e[i] + mu.Unlock() } }