From 36dbdd5d276524adae5f2edcb3c0aa26d4953cae Mon Sep 17 00:00:00 2001 From: starainrt Date: Thu, 23 Sep 2021 10:39:17 +0800 Subject: [PATCH] add lock --- typed.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/typed.go b/typed.go index 32ea688..32575eb 100644 --- a/typed.go +++ b/typed.go @@ -36,6 +36,7 @@ var ( stacks starmap.StarStack stackStarted bool = false stackStopChan chan int + stackMu sync.Mutex stdScreen io.Writer = colorable.NewColorableStdout() ) @@ -145,11 +146,14 @@ func generateId() string { } func StartStacks() { + stackMu.Lock() if stackStarted { + stackMu.Unlock() return } go func() { stackStarted = true + stackMu.Unlock() defer func() { stackStarted = false }()