#include "prism_engineering/worker_pool.hpp" #include #include int main() { using namespace prism_engineering; try { auto completed = run_batch({{7, {1, 2, 3}, false}, {6, {10, 20}, false}}, {2, {}}); if (!completed) return 1; std::cout << "Generation 7 checksum: " << completed->results[0].checksum << "\nOld generation accepted: " << std::boolalpha << accepts(completed->results[1], 7) << '\n'; auto gate = std::make_shared(); std::stop_source cancellation; // The controller owns its capture values; no coroutine or detached task. std::jthread controller{[gate, cancellation](std::stop_token stop) mutable { if (gate->wait_for_arrivals(2, stop)) cancellation.request_stop(); }}; const auto cancelled = run_batch({{8, {1, 2, 3}, false}}, {2, gate}, cancellation.get_token()); controller.request_stop(); // Also releases the controller if thread launch // failed. controller.join(); if (!cancelled || cancelled->results[0].status != Status::cancelled) return 1; std::cout << "Cancelled before computation; workers joined before return.\n"; return 0; } catch (...) { std::cerr << "Engineering experiment could not complete.\n"; return 1; } }