1 #include <boost/test/unit_test.hpp>
2 #include <boost/thread.hpp>
4 #define HAVE_SEMAPHORE_H
5 #include "utilities/ticket_scheduler.hpp"
13 nova::ticket_scheduler sched
;
15 void test_fn(std::size_t check
)
17 static std::size_t count
= 0;
19 BOOST_REQUIRE_EQUAL(count
, check
);
23 const int iterations
= 150;
26 void runme_nonblocking(void)
28 for (int i
= 0; i
!= iterations
; ++i
)
30 std::size_t ticket
= sched
.get_ticket();
32 boost::thread::yield();
36 if (sched
.run_nonblocking(ticket
, boost::bind(test_fn
, ticket
)))
39 boost::thread::yield();
47 for (int i
= 0; i
!= iterations
; ++i
)
49 std::size_t ticket
= sched
.get_ticket();
51 boost::thread::yield();
53 sched
.run(ticket
, boost::bind(test_fn
, ticket
));
60 BOOST_AUTO_TEST_CASE( ticket_scheduler_test
)
63 boost::thread_group threads
;
65 for (int i
= 0; i
!= thread_count
; ++i
)
67 threads
.create_thread(runme_nonblocking
);
74 boost::thread_group threads
;
76 for (int i
= 0; i
!= thread_count
; ++i
)
78 threads
.create_thread(runme
);