Browse Source

Fixed race condition

Loweel 4 years ago
parent
commit
1d89cbf698
1 changed files with 3 additions and 13 deletions
  1. 3 13
      file.go

+ 3 - 13
file.go

@@ -54,6 +54,9 @@ func saveBayesToFile() {
 
 	writeToFile(dumpfile+"stats.json", statsREPORT)
 
+	ZClassifier.Learning.busy.Lock()
+	defer ZClassifier.Learning.busy.Unlock()
+
 	badScores, err := json.MarshalIndent(ZClassifier.Learning.bayez.datas[Bad], "", " ")
 	if err != nil {
 		badScores = []byte(err.Error())
@@ -71,19 +74,6 @@ func saveBayesToFile() {
 
 	log.Println(string(goodScores))
 
-	//	dumpfile := os.Getenv("DUMPFILE")
-	//	if dumpfile == "" {
-	//		dumpfile = "bayes.json"
-	//	}
-
-	//	if DebugLog {
-	//		log.Println("DUMP: ", string(tmpJSON)+statsREPORT)
-	//	} else {
-	//		writeToFile(dumpfile, string(tmpJSON)+statsREPORT)
-	//
-	//		log.Println("File saved: ", dumpfile)
-	//	}
-
 }
 
 func jsonEngine() {