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

Pick 函数的规范实现 #54

Closed
samuelyao314 opened this issue Aug 20, 2018 · 8 comments
Closed

Pick 函数的规范实现 #54

samuelyao314 opened this issue Aug 20, 2018 · 8 comments

Comments

@samuelyao314
Copy link

更简洁的实现是

func (self *Pipe) Pick(retList *[]interface{}) (exit bool) {
self.listGuard.Lock()
defer self.listGuard.UnLock()

for len(self.list) == 0 {
	self.listCond.Wait()
}

// 复制出队列
   // 下面的代码保持一样的

}

@davyxu
Copy link
Owner

davyxu commented Aug 20, 2018

有性能测试保证稳定和正确性么?

@samuelyao314
Copy link
Author

参考的是 《Linux多线程服务端编程:使用muduo C++网络库》 第2.2 条件变量

@samuelyao314
Copy link
Author

如果你需要的话, 我把这本书的电子版发给你。 这边书的作者,说条件变量标准的正确实现只有这一种。

@samuelyao314
Copy link
Author

跟你的写法,具体的差别,我也不是很清楚

@davyxu
Copy link
Owner

davyxu commented Aug 20, 2018

对于你不清楚的东西,还是写测试用例证明. 任何修改都要对使用者负责,不能让别人当小白鼠

@samuelyao314
Copy link
Author

你测试的结果是二次lock 性能会比一次lock 好?

@davyxu
Copy link
Owner

davyxu commented Aug 20, 2018

当时只是解决带缓冲channel在数量过多时会死锁问题,换用现在修改解决问题
多次lock没有测试,别人提过来的代码一直是这样

@davyxu davyxu closed this as completed Sep 17, 2018
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