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 }