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

reduce sampler's mutex scope #1200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bengol
Copy link

@bengol bengol commented Aug 7, 2020

Change-Id: I7e413acedc8dfb93eae5c08243f0ff3e484f7059

问题: 线上环境中,进程退出时,hang在sampler->destroy()中的_mutex lock上,持有该_mutex的线程已经不再使用该锁且在正常运行,没有分析出发生路径

改动原因: _used变量无需_mutex保护,减少_mutex的范围来规避该问题。同时stop变量跨越了线程,需要atomic

Change-Id: I7e413acedc8dfb93eae5c08243f0ff3e484f7059
@bengol
Copy link
Author

bengol commented Nov 16, 2020

@zyearn 辛苦看下这个?理论分析上看是没有风险的

if (!s->_used) {
s->_mutex.unlock();
if (s->_used.load(butil::memory_order_acquire)) {
BAIDU_SCOPED_LOCK(s->_mutex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个_mutex也不太必要了,可以删掉

_mutex.lock();
_used = false;
_mutex.unlock();
_used.store(false, butil::memory_order_release);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要在注释里举一个场景说明一下为什么要release语意

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

Successfully merging this pull request may close these issues.

2 participants