21 #include <glog/logging.h> 28 using namespace folly;
34 auto foo =
new int(2);
42 des(
bool* d) : d_(d) {}
65 "Total time %li ns \n",
66 std::chrono::duration_cast<std::chrono::nanoseconds>(
diff).
count() /
74 rcu_retire<int>(
nullptr, [](
int*) {});
78 "Total time %li ns \n",
79 std::chrono::duration_cast<std::chrono::nanoseconds>(diff).
count() /
83 TEST(RcuTest, SlowReader) {
112 std::vector<std::thread>
threads;
114 std::atomic<int*> ints[sz];
116 ints[
i].store(
new int(0));
118 for (
unsigned th = 0; th < FLAGS_threads; th++) {
119 threads.push_back(std::thread([&]() {
120 for (
int i = 0;
i < FLAGS_iters / 100;
i++) {
125 ptrs[j] = ints[j].load(std::memory_order_acquire);
134 std::atomic<bool> done{
false};
135 std::thread updater([&]() {
136 while (!done.load()) {
137 auto newint =
new int(0);
139 rcu_retire<int>(oldint, [](
int* obj) {
145 for (
auto&
t : threads) {
153 delete ints[
i].exchange(
nullptr);
158 std::vector<std::thread>
threads;
159 for (
unsigned th = 0; th < FLAGS_threads; th++) {
160 threads.push_back(std::thread([&]() {
161 for (
int i = 0;
i < 10;
i++) {
166 for (
auto&
t : threads) {
177 TEST(RcuTest, NewDomainGuardTest) {
202 TEST(RcuTest, SynchronizeInCall) {
207 TEST(RcuTest, MoveReaderBetweenThreads) {
224 auto pid2 =
wait(&status);
234 TEST(RcuTest, ThreadLocalList) {
237 std::vector<std::thread>
threads{FLAGS_threads};
238 std::atomic<unsigned long> done{FLAGS_threads};
240 tr = std::thread([&]() {
241 for (
int i = 0;
i < FLAGS_iters;
i++) {
248 while (done.load() > 0) {
255 for (
auto& thread : threads) {
277 bool retired =
false;
280 base_test(
bool* ret) : ret_(ret) {}
286 auto foo =
new base_test(&retired);
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
std::chrono::steady_clock::time_point now()
DEFINE_uint64(threads, 32,"Number of threads")
—— Concurrent Priority Queue Implementation ——
DEFINE_int64(threadtimeout_ms, 60000,"Idle time before ThreadPoolExecutor threads are joined")
std::vector< std::thread::id > threads
Encoder::MutableCompressedList list
void rcu_retire(T *p, D d={}, rcu_domain< Tag > *domain=rcu_default_domain())
bool wait(Waiter *waiter, bool shouldSleep, Waiter *&next)
rcu_domain< RcuTag > * rcu_default_domain()
void collect(ListHead &list)
#define EXPECT_TRUE(condition)
void rcu_barrier(rcu_domain< Tag > *domain=rcu_default_domain()) noexcept
uint64_t diff(uint64_t a, uint64_t b)
#define EXPECT_FALSE(condition)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
rcu_reader tryretire(des *obj)
void synchronize_rcu(rcu_domain< Tag > *domain=rcu_default_domain()) noexcept