Skip to content

Commit d3a1e75

Browse files
committed
Added test that churns implicit producer threds (relates to cameron314#288)
1 parent 12b5206 commit d3a1e75

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/unittests/unittests.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,14 @@ class ConcurrentQueueTests : public TestClass<ConcurrentQueueTests>
349349
REGISTER_TEST(index_wrapping);
350350
REGISTER_TEST(subqueue_size_limit);
351351
REGISTER_TEST(exceptions);
352+
REGISTER_TEST(implicit_producer_churn);
352353
REGISTER_TEST(test_threaded);
353354
REGISTER_TEST(test_threaded_bulk);
354355
REGISTER_TEST(full_api<ConcurrentQueueDefaultTraits>);
355356
REGISTER_TEST(full_api<SmallIndexTraits>);
356357
REGISTER_TEST(blocking_wrappers);
357358
REGISTER_TEST(timed_blocking_wrappers);
359+
358360
//c_api/concurrentqueue
359361
REGISTER_TEST(c_api_create);
360362
REGISTER_TEST(c_api_enqueue);
@@ -3078,6 +3080,29 @@ class ConcurrentQueueTests : public TestClass<ConcurrentQueueTests>
30783080

30793081
return true;
30803082
}
3083+
3084+
bool implicit_producer_churn()
3085+
{
3086+
typedef TestTraits<4> Traits;
3087+
3088+
for (int i = 0; i != 256; ++i) {
3089+
std::vector<SimpleThread> threads(32);
3090+
ConcurrentQueue<int, Traits> q;
3091+
for (auto& thread : threads) {
3092+
SimpleThread t([&] {
3093+
int x;
3094+
for (int j = 0; j != 16; ++j) {
3095+
q.enqueue(0);
3096+
q.try_dequeue(x);
3097+
}
3098+
});
3099+
}
3100+
for (auto& thread : threads) {
3101+
thread.join();
3102+
}
3103+
}
3104+
return true;
3105+
}
30813106

30823107
bool test_threaded()
30833108
{

0 commit comments

Comments
 (0)