27 const int capacity = 256;
32 for (
unsigned int turn = 0; turn < turns; turn++) {
48 const int capacity = 256;
52 for (
unsigned int turn = 0; turn < turns; turn++) {
71 std::atomic<bool> readerHasRun(
false);
74 cursor.moveForward(3);
76 const int sentinel = 0xfaceb00c;
78 auto reader = std::thread([&]() {
85 for (
int i = 0;
i < 4;
i++) {
95 template <
typename T,
template <
typename>
class Atom>
99 struct ExposedCursor : RBCursor {
100 ExposedCursor(
const RBCursor& cursor) : RBCursor(cursor) {}
105 return ExposedCursor(rbcursor).value();
108 template <
template <
typename>
class Atom>
111 std::atomic<int32_t>& writes) {
113 while ((idx = writes--) > 0) {
118 template <
template <
typename>
class Atom>
122 DeterministicSchedule sched(DeterministicSchedule::uniform(0));
125 std::atomic<int32_t> writes_remaining(writes);
126 std::vector<std::thread>
threads(writers);
128 for (
int i = 0;
i < writers;
i++) {
129 threads[
i] = DeterministicSchedule::thread(
130 std::bind(runReader<Atom>, std::ref(rb), std::ref(writes_remaining)));
133 for (
auto& thread : threads) {
144 runWritesNeverFail<DeterministicAtomic>(1, 100, 4);
145 runWritesNeverFail<DeterministicAtomic>(10, 100, 4);
146 runWritesNeverFail<DeterministicAtomic>(100, 1000, 8);
147 runWritesNeverFail<DeterministicAtomic>(1000, 10000, 16);
149 runWritesNeverFail<std::atomic>(1, 100, 4);
150 runWritesNeverFail<std::atomic>(10, 100, 4);
151 runWritesNeverFail<std::atomic>(100, 1000, 8);
152 runWritesNeverFail<std::atomic>(1000, 10000, 16);
154 runWritesNeverFail<EmulatedFutexAtomic>(1, 100, 4);
155 runWritesNeverFail<EmulatedFutexAtomic>(10, 100, 4);
156 runWritesNeverFail<EmulatedFutexAtomic>(100, 1000, 8);
157 runWritesNeverFail<EmulatedFutexAtomic>(1000, 10000, 16);
161 const int capacity = 4;
162 const int rounds = 4;
166 cursor.moveForward(1);
169 for (
int i = 0;
i < capacity;
i++) {
182 EXPECT_EQ(capacity * (rounds - 1), result);
186 EXPECT_EQ((capacity * rounds) - 1, result);
190 const int capacity = 4;
194 auto (&cursorValue)(value<int, std::atomic>);
222 const int capacity = 3;
226 auto (&cursorValue)(value<int, std::atomic>);
228 int val = 0xfaceb00c;
239 const int capacity = 3;
243 auto (&cursorValue)(value<int, std::atomic>);
245 int val = 0xfaceb00c;
Cursor currentTail(double skipFraction=0.0) noexcept
void write(const T &in, folly::io::Appender &appender)
#define ASSERT_EQ(val1, val2)
bool waitAndTryRead(T &dest, const Cursor &cursor) noexcept
constexpr To round(std::chrono::duration< Rep, Period > const &d)
#define EXPECT_EQ(val1, val2)
DeterministicAtomicImpl< T, DeterministicSchedule > DeterministicAtomic
void runWritesNeverFail(int capacity, int writes, int writers)
—— Concurrent Priority Queue Implementation ——
static constexpr StringPiece ticket
std::vector< std::thread::id > threads
Cursor writeAndGetCursor(T &value) noexcept
#define EXPECT_TRUE(condition)
bool moveBackward(uint64_t steps=1) noexcept
void write(T &value) noexcept
int bind(NetworkSocket s, const sockaddr *name, socklen_t namelen)
void runReader(LockFreeRingBuffer< int, Atom > &rb, std::atomic< int32_t > &writes)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
Cursor currentHead() noexcept
Returns a Cursor pointing to the first write that has not occurred yet.
bool moveForward(uint64_t steps=1) noexcept
#define EXPECT_FALSE(condition)
#define ASSERT_TRUE(condition)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
bool tryRead(T &dest, const Cursor &cursor) noexcept