Skip to content

Add a concurrent structure: butil/containers/sync_map which inspired by sync.map in go#625

Closed
Aleda wants to merge 1 commit intoapache:masterfrom
Aleda:master
Closed

Add a concurrent structure: butil/containers/sync_map which inspired by sync.map in go#625
Aleda wants to merge 1 commit intoapache:masterfrom
Aleda:master

Conversation

@Aleda
Copy link

@Aleda Aleda commented Jan 20, 2019

No description provided.

@choleraehyq
Copy link
Contributor

这个好像 brpc 里并没有用到?

@jamesge
Copy link
Contributor

jamesge commented Feb 14, 2019

有多线程环境下的性能测试结果么?

@Aleda
Copy link
Author

Aleda commented Feb 16, 2019

是的,这个并不涉及brpc本身,只是作为一个单独数据结构提到butils作为借鉴与后续出现类似场景的使用。
多线程环境以及和其他类似实现的性能对比,我这边有一些数据,不过并没有细致的整理。
后面我提交一下相应的bench mark和性能数据。


namespace butil {

class LinkNode {
Copy link
Member

Choose a reason for hiding this comment

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

为什么需要重新实现linked list? container下面的不能满足需求?

LinkNode* _tail;
};

class sync_list {
Copy link
Member

Choose a reason for hiding this comment

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

这里采用class name 使用 snake name的理由是什么?

_head.store(node, std::memory_order_release);
}

bool cas_head(LinkNode* expected, LinkNode* node) noexcept {
Copy link
Member

Choose a reason for hiding this comment

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

lock free list使用cas是存在经典的ABA问题, 有gc的语言由于全局gc的存在不受到影响,这里确认这样是没问题的?


template <class Key, class Value, typename Hasher>
sync_map<Key, Value, Hasher>::~sync_map() {
butil::AutoLock lock(_lock);
Copy link
Member

Choose a reason for hiding this comment

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

析构为什么还有竞争?

@Aleda Aleda closed this Oct 28, 2019
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.

4 participants