- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 libcds他们实现了 Michael Hash Map 和 Split order list。
根据我从文档中收集到的信息,我是如何实现它们的:
包括:
#include <cds/map/michael_hash_map.h>
#include <cds/map/split_ordered_list.h>
using namespace cds;
代码:
class TestDs {
public:
virtual bool containsKey(int key)=0;
virtual int get(int key)=0;
virtual int put(int key, int value)=0;
virtual int remove(int key)=0;
virtual int size()=0;
virtual const char* name()=0;
virtual void print()=0;
virtual void shutdown()=0;
};
代码:
class Michael: public TestDs{
private:
cds::map::MichaelHashMap<int,int,cds::map::pair_traits <int, int>, cds::map::type_traits, CDS_DEFAULT_ALLOCATOR> _ds;
public:
Michael(const Configuration& config) : _ds(config.initial_count,config.load_factor) {
}
bool containsKey(int key) {
return (_ds.find(key)!=0);
}
int get(int key) {
return _ds.find(key);
}
int put(int key, int value) {
return _ds.insert(key,value);
}
int remove(int key) {
return _ds.erase(key);
}
int size() {
return _ds.size();
}
const char* name() {
return "Micheal";
}
void print() {}
void shutdown() {}
};
并且:
class CDSSplit: public TestDs{
private:
cds::map::SplitOrderedList<int,int,cds::map::pair_traits<int,int> ,cds::map::split_list::type_traits,CDS_DEFAULT_ALLOCATOR> _ds;
public:
CDSSplit(const Configuration& config) : _ds(config.initial_count, config.load_factor) {
}
bool containsKey(int key) {
return (_ds.find(key)!=0);
}
int get(int key) {
return _ds.find(key);
}
int put(int key, int value) {
return _ds.insert(key,value);
}
int remove(int key) {
return _ds.erase(key);
}
int size() {
return _ds.size();
}
const char* name() {
return "CDSSPlit";
}
void print() {}
void shutdown() {}
};
我通过调用来启动结构:
TestDs* _gTestDs1 = new Michael(_gConfiguration);
TestDs* _gTestDs2 = new CDSSplit(_gConfiguration);
但是,当 CDSSplit 启动时,或者当 Michael 执行第一次插入时,我会遇到段错误。
库安装正常,没有任何警告,我使用其他哈希表也没有收到任何错误。
感谢您的帮助
(也发布了,在图书馆的讨论页面上的细节较少,但那里似乎没有太多存在,如果有任何内容发布在那里会回发)
编译标志:-std=c++0x -O3 -msse2 -m32 -DNDEBUG -DINTEL -g -D_REENTRANT -lrt -pthread -fno-strict-aliasing -l cds -l tbb -lllalloc
GDB 输出:
Program received signal SIGSEGV, Segmentation fault.
cds::ordered_list::details::michael_list::implementation<cds::gc::hzp_gc, cds::ordered_list::details::michael_list::adapter<cds::gc::hzp_gc, int, int, cds::map::pair_traits<int, int>, cds::ordered_list::type_traits, std::allocator<int> >, std::allocator<int> >::insert (this=0xafd42028, refHead=..., pNode=0x8440060) at /usr/include/cds/ordered_list/details/michael_list_hpgen.h:457
457 position pos( gc_base_class::getGC() ) ;
(gdb) backtrace
#0 cds::ordered_list::details::michael_list::implementation<cds::gc::hzp_gc, cds::ordered_list::details::michael_list::adapter<cds::gc::hzp_gc, int, int, cds::map::pair_traits<int, int>, cds::ordered_list::type_traits, std::allocator<int> >, std::allocator<int> >::insert (this=0xafd42028, refHead=..., pNode=0x8440060) at /usr/include/cds/ordered_list/details/michael_list_hpgen.h:457
#1 0x0805323e in insert (this=0x8470070, key=2, value=2) at /usr/include/cds/ordered_list/details/michael_list_hpgen.h:430
#2 insert (this=0x8470070, key=2, value=2) at /usr/include/cds/ordered_list/details/michael_list_hpgen.h:195
#3 insert (this=0x8470070, key=2, value=2) at /usr/include/cds/map/michael_hash_map.h:487
#4 Michael::put (this=0x8470070, key=2, value=2) at ../test/main.cpp:450
#5 0x0804b129 in FillTable (table_size=5033165) at ../test/main.cpp:876
#6 0x0804c7b2 in RunBenchmark () at ../test/main.cpp:961
#7 0x0804e617 in main (argc=9, argv=0xbffff714) at ../test/main.cpp:846
最佳答案
根据 the docs , 看起来你是 missing the initialization of CDS and the threading manager :
#include <cds/threading/model.h> // threading manager
#include <cds/gc/hzp/hzp.h> // Hazard Pointer GC
// ...
int main()
{
// Initialize CDS library
cds::Initialize() ;
// Initialize Garbage collector(s) that you use
cds::gc::hzp::GarbageCollector::Construct() ;
// attach this thread to CDS:
cds::threading::Manager::attachThread() ;
// Do some useful work
Configuration _gConfiguration;
TestDs* _gTestDs1 = new Michael(_gConfiguration);
TestDs* _gTestDs2 = new CDSSplit(_gConfiguration);
// Terminate GCs
cds::gc::hzp::GarbageCollector::Destruct() ;
// Terminate CDS library
cds::Terminate() ;
return 0;
}
关于c++ - LibCds:Michael Hashmap 和 Split Order List,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6632234/
我正在使用 libcds他们实现了 Michael Hash Map 和 Split order list。 根据我从文档中收集到的信息,我是如何实现它们的: 包括: #include #inclu
尝试编译我下载的一些代码时,出现链接错误 LNK1104:无法打开文件“LIBCD.lib”。我无法在我的电脑上的任何地方找到这个文件。它是什么,我可以从某个地方下载吗?还有另一种方法可以使代码工作吗
我已经将 VolPack ( https://graphics.stanford.edu/software/volpack/ ) 编译为 Visual Studio 6(在 Windows XP 下)
所以我真的很想看到一些并行的速度测试(比如从 100 到 10000 个并行线程),其中每个线程至少在 3 种类型的并发映射上插入、查找、删除 - std::map(有一些互斥锁)与 libcds (
我是一名优秀的程序员,十分优秀!