Fix random value of CachedReader at first time #2556
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number:
Problem Summary:
CachedReader::get_value中fn没有在锁内执行,第一次执行get_value的时候,可能会读到_cache的初始值。由于_cache没有显式初始化,而且实际的类型(如ProcMemory、ProcStat)没有实现默认构造函数,所以成员变量的值是随机值。相对于随机值,值为0,让人更好理解一些。
brpc/src/bvar/default_variables.cpp
Lines 147 to 163 in 24fc31e
What is changed and the side effects?
Changed:
Side effects:
Performance effects(性能影响):
Breaking backward compatibility(向后兼容性):
Check List: