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

极端情况 #4

Closed
shangxiaomi opened this issue Mar 9, 2021 · 1 comment
Closed

极端情况 #4

shangxiaomi opened this issue Mar 9, 2021 · 1 comment

Comments

@shangxiaomi
Copy link

shangxiaomi commented Mar 9, 2021

考虑一个极端的例子
假设pool的容量为1

func (p *GoPool) Put(task *Task) error {
	if p.getState() == STOPED { 
		return ErrPoolAlreadyClosed
	}
	p.Lock()
	if p.GetRunningWorkers() < p.GetCap() {
		p.run()
	}
	p.Unlock()
        //假设之前已经put了一个任务,要再put一个任务
        //当程序执行到这里,如果之前put的任务突然panic了,其实,这时候没有可以执行任务的协程了
        //下面的task发送不出去,并且之后也没有新的任务进来,就会永远阻塞这里。
	p.Lock()
	if p.state == RUNNING {
		p.taskC <- task
	}
	p.Unlock()
	return nil
}

会有这种情况吧

wazsmwazsm pushed a commit that referenced this issue Mar 15, 2021
@wazsmwazsm
Copy link
Owner

@shangxiaomi 感谢提出这个问题,已经修复到 release v1.5 中,现在 worker 结束后会检查是否没有可用 worker 确保至少有一个 worker 可以消费任务

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