Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问下池子为什么每次要lock呢 #19

Open
XxYyKk opened this issue Mar 27, 2019 · 2 comments
Open

请问下池子为什么每次要lock呢 #19

XxYyKk opened this issue Mar 27, 2019 · 2 comments

Comments

@XxYyKk
Copy link

XxYyKk commented Mar 27, 2019

请问下 pool 为什么每次要 lock ,是什么考虑呢

// getConns 获取所有连接
func (c *channelPool) getConns() chan *idleConn {
c.mu.Lock()
conns := c.conns
c.mu.Unlock()

@yoloyi
Copy link

yoloyi commented Nov 17, 2019

考虑并发的时候,获取链接的时候冲突,所以要把这个地方锁住,等拿出来了。再释放。掉锁

@yaicc
Copy link

yaicc commented Jan 24, 2022

conns本身就是chan,没有必要再加读锁吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@yaicc @XxYyKk @yoloyi and others