@@ -52,6 +52,38 @@ void call_pull(sync_tq* q)
5252 }
5353}
5454
55+ void call_pull_until (sync_tq* q)
56+ {
57+ // pull elements off of the queue (earliest element first)
58+ steady_clock::time_point start = steady_clock::now ();
59+ for (int i = count - 1 ; i >= 0 ; --i)
60+ {
61+ int j;
62+ q->pull_until (steady_clock::now () + hours (1 ), j);
63+ BOOST_TEST_EQ (i, j);
64+ milliseconds elapsed = duration_cast<milliseconds>(steady_clock::now () - start);
65+ milliseconds expected = milliseconds (i * 500 ) + seconds (count - i);
66+ BOOST_TEST_GE (elapsed, expected - milliseconds (BOOST_THREAD_TEST_TIME_MS));
67+ BOOST_TEST_LE (elapsed, expected + milliseconds (BOOST_THREAD_TEST_TIME_MS));
68+ }
69+ }
70+
71+ void call_pull_for (sync_tq* q)
72+ {
73+ // pull elements off of the queue (earliest element first)
74+ steady_clock::time_point start = steady_clock::now ();
75+ for (int i = count - 1 ; i >= 0 ; --i)
76+ {
77+ int j;
78+ q->pull_for (hours (1 ), j);
79+ BOOST_TEST_EQ (i, j);
80+ milliseconds elapsed = duration_cast<milliseconds>(steady_clock::now () - start);
81+ milliseconds expected = milliseconds (i * 500 ) + seconds (count - i);
82+ BOOST_TEST_GE (elapsed, expected - milliseconds (BOOST_THREAD_TEST_TIME_MS));
83+ BOOST_TEST_LE (elapsed, expected + milliseconds (BOOST_THREAD_TEST_TIME_MS));
84+ }
85+ }
86+
5587void test_push_while_pull ()
5688{
5789 sync_tq tq;
@@ -63,8 +95,32 @@ void test_push_while_pull()
6395 BOOST_TEST (tq.empty ());
6496}
6597
98+ void test_push_while_pull_until ()
99+ {
100+ sync_tq tq;
101+ BOOST_TEST (tq.empty ());
102+ boost::thread_group tg;
103+ tg.create_thread (boost::bind (call_push, &tq));
104+ tg.create_thread (boost::bind (call_pull_until, &tq));
105+ tg.join_all ();
106+ BOOST_TEST (tq.empty ());
107+ }
108+
109+ void test_push_while_pull_for ()
110+ {
111+ sync_tq tq;
112+ BOOST_TEST (tq.empty ());
113+ boost::thread_group tg;
114+ tg.create_thread (boost::bind (call_push, &tq));
115+ tg.create_thread (boost::bind (call_pull_for, &tq));
116+ tg.join_all ();
117+ BOOST_TEST (tq.empty ());
118+ }
119+
66120int main ()
67121{
68122 test_push_while_pull ();
123+ test_push_while_pull_until ();
124+ test_push_while_pull_for ();
69125 return boost::report_errors ();
70126}
0 commit comments