29 explicit MyObject(
int i_) :
i(i_) {}
34 typedef std::lock_guard<std::mutex> Guard;
36 std::unique_ptr<MyMap> newMap() {
37 return std::make_unique<MyMap>(100);
40 struct MyObjectDirectory {
41 MyObjectDirectory() : cur_(newMap()), prev_(newMap()) {}
43 std::shared_ptr<MyObject>
get(
int key) {
44 auto val = tryGet(key);
49 std::shared_ptr<MyMap> cur;
55 auto ret = cur->insert(key, std::make_shared<MyObject>(key));
56 return ret.first->second;
59 std::shared_ptr<MyObject> tryGet(
int key) {
60 std::shared_ptr<MyMap> cur;
61 std::shared_ptr<MyMap> prev;
68 auto it = cur->find(key);
69 if (it != cur->end()) {
74 if (it != prev->end()) {
75 auto ret = cur->insert(key, it->second);
76 return ret.first->second;
83 std::shared_ptr<MyMap> cur(newMap());
91 std::shared_ptr<MyMap> cur_;
92 std::shared_ptr<MyMap> prev_;
105 auto const objs =
new MyObjectDirectory();
110 std::vector<std::thread>
threads;
111 for (
int threadId = 0; threadId < 64; ++threadId) {
112 threads.emplace_back([objs] {
113 for (
int recycles = 0; recycles < 500; ++recycles) {
114 for (
int i = 0;
i < 10;
i++) {
115 auto val = objs->get(
i);
123 for (
auto&
t : threads) {
TEST(AHMIntStressTest, Test)
std::vector< std::thread::id > threads