2022-02-22 20:33:45 +08:00
|
|
|
// Copyright 2022 Memgraph Ltd.
|
2021-10-26 14:53:56 +08:00
|
|
|
//
|
|
|
|
// Use of this software is governed by the Business Source License
|
|
|
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
|
|
// License, and you may not use this file except in compliance with the Business Source License.
|
|
|
|
//
|
|
|
|
// As of the Change Date specified in that file, in accordance with
|
|
|
|
// the Business Source License, use of this software will be governed
|
|
|
|
// by the Apache License, Version 2.0, included in the file
|
|
|
|
// licenses/APL.txt.
|
|
|
|
|
2019-01-14 18:11:51 +08:00
|
|
|
#include <thread>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "utils/skip_list.hpp"
|
|
|
|
|
|
|
|
const int kNumThreads = 8;
|
|
|
|
const uint64_t kMaxNum = 10000000;
|
|
|
|
|
|
|
|
int main() {
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::utils::SkipList<uint64_t> list;
|
2019-01-14 18:11:51 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < kMaxNum * kNumThreads; ++i) {
|
|
|
|
auto acc = list.access();
|
|
|
|
auto ret = acc.insert(i);
|
2021-01-21 22:47:56 +08:00
|
|
|
MG_ASSERT(ret.first != acc.end());
|
|
|
|
MG_ASSERT(ret.second);
|
2019-01-14 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::thread> threads;
|
|
|
|
for (int i = 0; i < kNumThreads; ++i) {
|
|
|
|
threads.push_back(std::thread([&list, i] {
|
|
|
|
for (uint64_t num = i * kMaxNum; num < (i + 1) * kMaxNum; ++num) {
|
|
|
|
auto acc = list.access();
|
2021-01-21 22:47:56 +08:00
|
|
|
MG_ASSERT(acc.remove(num));
|
2019-01-14 18:11:51 +08:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < kNumThreads; ++i) {
|
|
|
|
threads[i].join();
|
|
|
|
}
|
|
|
|
|
2021-01-21 22:47:56 +08:00
|
|
|
MG_ASSERT(list.size() == 0);
|
2019-01-14 18:11:51 +08:00
|
|
|
uint64_t count = 0;
|
|
|
|
auto acc = list.access();
|
|
|
|
for (auto it = acc.begin(); it != acc.end(); ++it) {
|
|
|
|
++count;
|
|
|
|
}
|
2021-01-21 22:47:56 +08:00
|
|
|
MG_ASSERT(count == 0);
|
2019-01-14 18:11:51 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|