From 1eaea40a50475bd6e96c792d0ff4acb4ae1481ce Mon Sep 17 00:00:00 2001 From: lwch Date: Fri, 27 Aug 2021 14:21:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=90=AF=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E8=BF=9E=E6=8E=A5ID=E5=86=B2=E7=AA=81?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/client/pool/pool.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/code/client/pool/pool.go b/code/client/pool/pool.go index 2334403..bd2f3dd 100644 --- a/code/client/pool/pool.go +++ b/code/client/pool/pool.go @@ -5,6 +5,7 @@ import ( "natpass/code/client/global" "natpass/code/network" "sync" + "sync/atomic" "time" "github.com/lwch/logging" @@ -58,12 +59,12 @@ func (p *Pool) Get(id ...string) *Conn { return conn } - p.idx++ - conn := p.connect(p.idx) + idx := atomic.AddUint32(&p.idx, 1) + conn := p.connect(idx) if conn == nil { return nil } - c := newConn(p, conn, p.idx) + c := newConn(p, conn, idx) p.Lock() p.conns[c.Idx] = c