ui::Scheduler¶
Header: winui/core/Scheduler.hpp.
A pool of worker threads for background work and parallel layout.
Construct one to give a piece of work its own threads, and hand it to ui::on_background(pool) or to ParallelLayout::scheduler. Work on a pool must not touch the UI tree. The Inline mode runs everything synchronously on the calling thread, for deterministic tests. The destructor runs every job still queued, then joins the workers.
Example:
// Two threads of its own, so an index never waits behind other background work.
ui::Scheduler indexers{2};
// `status` is app state that outlives the window, shown by a Text bound to it.
ui::FireAndForget index(ui::Scheduler& indexers, ui::Window& window, ui::Property<std::string>& status,
std::filesystem::path folder)
{
const ui::WindowRef home = window.ref();
co_await ui::on_background(indexers); // on one of the pool's threads
const auto files = std::distance(std::filesystem::recursive_directory_iterator{folder}, {});
co_await ui::on_ui_thread(home);
status = std::format("{} files", files);
}
Scheduler¶
Real worker threads. thread_count == 0 auto-detects: max(1, hardware_concurrency()).
Scheduler¶
The deterministic mode (see Inline): no threads.
~Scheduler¶
Runs every job still queued, then joins the worker threads.
Scheduler¶
Not copyable: it owns threads.
operator=¶
Not copyable: it owns threads.
thread_count¶
Real worker thread count (0 in inline mode).
worker_count¶
How many jobs can run at once: thread_count(), and 1 in inline mode. Parallel layout splits its measuring into this many chunks.
struct Inline¶
Tag selecting the deterministic mode for tests: work runs synchronously, in the order it was queued, on the calling thread, with no worker threads and no interleaving. Construct with Scheduler{Scheduler::Inline{}}.