-
Notifications
You must be signed in to change notification settings - Fork 63
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
improvement(hashmap): use folly ConcurrentHashMap replace unordered_map #29
improvement(hashmap): use folly ConcurrentHashMap replace unordered_map #29
Conversation
Centurybbx
commented
Nov 4, 2023
- 多线程改造:使用folly::ConcurrentHashMap来替换std::unordered_map
- Work in progress...
clients.push_back(Clients::value_type(std::static_pointer_cast<PClient>(client->shared_from_this()), timeout, pos)); | ||
auto it = blockedClients_.find(key); | ||
if (it != blockedClients_.end()) { | ||
// since folly doesn't support modify value directly, we have to make a copy to update atomically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里有没有并发安全问题?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
迭代器是一个不可变量;此外在官方的示例中,如果当前线程获取了某个迭代器,其余线程的更改对于当前线程是感知不到的,因此我认为是线程安全的
src/helper.h
Outdated
} | ||
|
||
it = container.cbegin(); | ||
size_t randomIdx = random() % container.size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里随机函数推荐使用 C++的随机函数, 像这里的
pikiwidb/src/pstd/pstd_string.cc
Line 409 in e05878d
std::random_device rd; |
这里我的锅, 在移植 pstd的时候, 没有把 随机函数 单独 包装好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/store.cc
Outdated
@@ -200,7 +210,7 @@ size_t PStore::BlockedClients::UnblockClient(PClient* client) { | |||
const auto& keys = client->WaitingKeys(); | |||
|
|||
for (const auto& key : keys) { | |||
Clients& clients = blockedClients_[key]; | |||
Clients clients = blockedClients_[key]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里用find会不会更好一点
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯对,这里应该用find的