25 #include <glog/logging.h> 30 using namespace folly;
36 explicit Semaphore(
int v = 0) : value_(
v) {}
39 ec_.await([
this] {
return tryDown(); });
53 for (
int v = value_;
v != 0;) {
54 if (value_.compare_exchange_weak(
v,
v - 1)) {
61 std::atomic<int> value_;
65 template <
class T,
class Random>
70 std::vector<std::pair<T, int>>& out) {
73 std::uniform_int_distribution<uint32_t> u(1, m);
75 out.emplace_back(key, cut);
84 static const size_t count = 300000;
90 std::vector<std::pair<Op, int>>
ops;
92 randomPartition(rnd, Op::UP, count, ops);
93 size_t uppers = ops.size();
94 randomPartition(rnd, Op::DOWN, count, ops);
95 size_t downers = ops.size() - uppers;
96 VLOG(1) <<
"Using " << ops.size() <<
" threads: uppers=" << uppers
97 <<
" downers=" << downers <<
" sem_count=" <<
count;
99 std::shuffle(ops.begin(), ops.end(), std::mt19937(std::random_device()()));
101 std::vector<std::thread>
threads;
102 threads.reserve(ops.size());
105 for (
auto&
op : ops) {
107 if (
op.first == Op::UP) {
108 auto fn = [&sem, n]()
mutable {
113 threads.push_back(std::thread(fn));
115 auto fn = [&sem, n]()
mutable {
120 threads.push_back(std::thread(fn));
124 for (
auto& thread : threads) {
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
—— Concurrent Priority Queue Implementation ——
std::vector< std::thread::id > threads
static map< string, int > m
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
uint32_t randomNumberSeed()
TEST(SequencedExecutor, CPUThreadPoolExecutor)