From 4898116698a6cafa0aed18de57562b1735a6fafe Mon Sep 17 00:00:00 2001 From: boyce Date: Tue, 27 Feb 2024 16:18:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96concurrent=EF=BC=8C=E7=A6=81?= =?UTF-8?q?=E6=AD=A2=E9=87=8D=E5=A4=8D=E6=89=93=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- concurrent/concurrent.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/concurrent/concurrent.go b/concurrent/concurrent.go index 6b97059..702c020 100644 --- a/concurrent/concurrent.go +++ b/concurrent/concurrent.go @@ -5,6 +5,7 @@ import ( "runtime" "github.com/duanhf2012/origin/log" + "sync/atomic" ) const defaultMaxTaskChannelNum = 1000000 @@ -21,6 +22,7 @@ type Concurrent struct { tasks chan task cbChannel chan func(error) + open int32 } /* @@ -33,6 +35,10 @@ func (c *Concurrent) OpenConcurrentByNumCPU(cpuNumMul float32) { } func (c *Concurrent) OpenConcurrent(minGoroutineNum int32, maxGoroutineNum int32, maxTaskChannelNum int) { + if atomic.AddInt32(&c.open,1) > 1 { + panic("repeated calls to OpenConcurrent are not allowed!") + } + c.tasks = make(chan task, maxTaskChannelNum) c.cbChannel = make(chan func(error), maxTaskChannelNum)