From 9ab6c82a4a8a472be7ae2b755c77ce59df6774dd Mon Sep 17 00:00:00 2001 From: Rinsvent Date: Mon, 23 Sep 2024 00:09:50 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- thread.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/thread.go b/thread.go index 8064df7..219adb2 100644 --- a/thread.go +++ b/thread.go @@ -16,12 +16,8 @@ type Manager struct { func (m *Manager) Start(f func()) { m.stopped = make(chan bool, 1) for { - if m.runningCount.Load() >= m.Count { - continue - } - if m.stop { - if m.runningCount.Load() <= 1 { + if m.runningCount.Load() < 1 { gol.Debug("thread manager stopped") m.stopped <- true break @@ -30,7 +26,12 @@ func (m *Manager) Start(f func()) { continue } + if m.runningCount.Load() >= m.Count { + continue + } + if m.runningCount.Add(1) > m.Count { + m.runningCount.Add(-1) gol.Debug("thread manager atomic skip") continue }