Theme Catppuccin
Make yourself at homeCatppuccin

A softer light for long learning sessions.

Appearance

Loading your preference…

Dark palette

Choose a dark palette to try it.

Light uses Latte. Your choices stay in this browser.

Back to your source shelf

Inside the companion

Renderer Engineering

Explore bounded image work, allocator lifetimes, cancellation, and Asio coroutines.

Project files 15

Run the blocking baseline

Submit a small checksum batch and inspect its completion and publication policy.

37 lines experiment.cpp
#include "prism_engineering/worker_pool.hpp"
#include <iostream>
#include <thread>

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<WorkGate>();
    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;
  }
}

This is the file included with the course. Copy and download give you its complete source.

Taking your work offline? Download all course companions