From 805db5088b6f838dd9b42c4b4f02627f59c6146f Mon Sep 17 00:00:00 2001 From: surtur Date: Fri, 5 Aug 2022 17:23:10 +0200 Subject: [PATCH] go(algo): close chans after use --- algo/algo.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/algo/algo.go b/algo/algo.go index 2e64618..c07986b 100644 --- a/algo/algo.go +++ b/algo/algo.go @@ -143,6 +143,8 @@ func DoRandomSearch(wg *sync.WaitGroup, m *sync.Mutex) { // ch serves as a way to get the actual computed output. ch := make(chan []stats.Stats, funcCount) + defer close(ch) + for i := range algoStats { // ng y'all. go RandomSearchNG(10000, 30, bench.Dimensions, bench.FuncNames[i], ch) @@ -158,6 +160,9 @@ func DoRandomSearch(wg *sync.WaitGroup, m *sync.Mutex) { pCh := make(chan report.PicList, funcCount*len(bench.Dimensions)) pMeanCh := make(chan report.PicList, funcCount*len(bench.Dimensions)) + defer close(pCh) + defer close(pMeanCh) + for i := range algoStats { go plotAllDims(algoStats[i], "plot", ".svg", pCh, pMeanCh) } @@ -197,6 +202,8 @@ func DoStochasticHillClimbing(wg *sync.WaitGroup, m *sync.Mutex) { // ch serves as a way to get the actual computed output. ch := make(chan []stats.Stats, funcCount) + defer close(ch) + for i := range algoStats { // params: // maxFES, benchMinIters, neighbours int, @@ -216,6 +223,9 @@ func DoStochasticHillClimbing(wg *sync.WaitGroup, m *sync.Mutex) { pCh := make(chan report.PicList, funcCount*len(bench.Dimensions)) pMeanCh := make(chan report.PicList, funcCount*len(bench.Dimensions)) + defer close(pCh) + defer close(pMeanCh) + for _, algoStat := range algoStats { go plotAllDims(algoStat, "plot", ".svg", pCh, pMeanCh) }