2018-03-15 15:21:05 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2017-07-03 17:05:01 +10:00
|
|
|
#include "job/queue.hpp"
|
|
|
|
#include "tap.hpp"
|
|
|
|
|
2018-03-15 15:21:05 +11:00
|
|
|
#include <chrono>
|
2017-07-03 17:05:01 +10:00
|
|
|
|
2018-03-15 15:21:05 +11:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2017-07-03 17:05:01 +10:00
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
|
|
|
util::TAP::logger tap;
|
|
|
|
|
|
|
|
// dispatch `INNER' simple jobs `OUTTER' times that simply increment an
|
|
|
|
// atomic variable and quit. this tests that all threads are created,
|
|
|
|
// executed, and finished. it's not definitive, but executing this many
|
|
|
|
// items this many times seems reasonably reliable in exposing deadlocks.
|
|
|
|
bool success = true;
|
2018-03-15 15:21:05 +11:00
|
|
|
constexpr int OUTTER = 1;
|
|
|
|
constexpr int INNER = 1;
|
2017-07-03 17:05:01 +10:00
|
|
|
|
|
|
|
for (auto i = 0; i < OUTTER && success; ++i) {
|
|
|
|
std::atomic<int> count = 0;
|
|
|
|
|
|
|
|
{
|
2018-03-15 15:21:05 +11:00
|
|
|
util::job::queue q {1};
|
|
|
|
std::vector<util::job::queue::cookie> cookies;
|
|
|
|
for (int j = 0; j < INNER; ++j) {
|
|
|
|
cookies.push_back (
|
|
|
|
q.submit ([&count] (int sleep_for) noexcept {
|
|
|
|
std::this_thread::sleep_for (std::chrono::microseconds (sleep_for % 25));
|
|
|
|
++count;
|
|
|
|
}, j)
|
|
|
|
);
|
|
|
|
}
|
2017-07-03 17:05:01 +10:00
|
|
|
}
|
|
|
|
|
2018-03-15 15:21:05 +11:00
|
|
|
std::cout << count << '\n';
|
|
|
|
|
2017-07-03 17:05:01 +10:00
|
|
|
success = count == INNER && success;
|
|
|
|
}
|
|
|
|
|
|
|
|
tap.expect (success, "trivial increment jobs");
|
|
|
|
return tap.status ();
|
|
|
|
}
|