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

running可能大于cap的问题 #26

Closed
Ainiroad opened this issue Feb 25, 2019 · 2 comments
Closed

running可能大于cap的问题 #26

Ainiroad opened this issue Feb 25, 2019 · 2 comments

Comments

@Ainiroad
Copy link

running与cap的比较判断与incRuning分开执行的, 可能会出现running大于cap的问题?
`func (p *Pool) retrieveWorker() *Worker {
var w *Worker

p.lock.Lock()
idleWorkers := p.workers
n := len(idleWorkers) - 1
if n >= 0 {
	w = idleWorkers[n]
	idleWorkers[n] = nil
	p.workers = idleWorkers[:n]
	p.lock.Unlock()
} else if p.Running() < p.Cap() {
	p.lock.Unlock()
	if cacheWorker := p.workerCache.Get(); cacheWorker != nil {
		w = cacheWorker.(*Worker)
	} else {
		w = &Worker{
			pool: p,
			task: make(chan func(), workerChanCap),
		}
	}
	w.run()`
@panjf2000
Copy link
Owner

不会的,incRunning操作总是在比较大小之后才发生的。

@panjf2000
Copy link
Owner

合并到#28

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

2 participants