class library: Reset has been renamed to OnError
[supercollider.git] / testsuite / supernova / ticket_scheduler_test.cpp
blob288b0be935cccff3ac745cc6cd05bd89460e40e4
1 #include <boost/test/unit_test.hpp>
2 #include <boost/thread.hpp>
4 #define HAVE_SEMAPHORE_H
5 #include "utilities/ticket_scheduler.hpp"
8 namespace
11 int thread_count = 5;
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);
20 ++count;
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();
34 for(;;)
36 if (sched.run_nonblocking(ticket, boost::bind(test_fn, ticket)))
37 break;
38 else
39 boost::thread::yield();
45 void runme(void)
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);
70 threads.join_all();
74 boost::thread_group threads;
76 for (int i = 0; i != thread_count; ++i)
78 threads.create_thread(runme);
81 threads.join_all();