diff --git a/exercises/basics/06-concurrency/01-goroutines/src_test.go b/exercises/basics/06-concurrency/01-goroutines/src_test.go index d43bc16..35c531f 100644 --- a/exercises/basics/06-concurrency/01-goroutines/src_test.go +++ b/exercises/basics/06-concurrency/01-goroutines/src_test.go @@ -14,7 +14,7 @@ func TestExecute(t *testing.T) { func() { buffers := make(chan *bytes.Buffer) go func(done chan *bytes.Buffer) { - buffers <- Execute(10) + done <- Execute(10) }(buffers) select { diff --git a/solutions/basics/06-concurrency/01-goroutines/src.go b/solutions/basics/06-concurrency/01-goroutines/src.go index 0c6a233..1a540d6 100644 --- a/solutions/basics/06-concurrency/01-goroutines/src.go +++ b/solutions/basics/06-concurrency/01-goroutines/src.go @@ -10,6 +10,9 @@ import ( // Maybe if we ran all the long processes concurrently, it would be much faster. // Let's do that! // Beware, all the processes must end before that Execute returns. + +var m sync.Mutex + func Execute(nbProcess int) *bytes.Buffer { buf := new(bytes.Buffer) wg := &sync.WaitGroup{} @@ -26,5 +29,7 @@ func Execute(nbProcess int) *bytes.Buffer { func someReallyLongProcess(buf *bytes.Buffer) { time.Sleep(1 * time.Second) + m.Lock() + defer m.Unlock() buf.WriteString("Done\n") }