Crafter.Thread/project.cpp
Jorijn van der Graaf f71cb43e85
fix(threadpool): batches run every task once, and Stop ends the whole pool
- Enqueue(vector) dropped tasks when the count didn't divide by the
  workers: the last one got only the remainder. Tasks are now split as
  evenly as the count allows, each worker's taskCount grows by what it
  was given (the single-task Enqueue picks by it), and Start(1), which
  has no workers, leaves the batch for the caller's JoinPool.
- Stop wakes every slot, JoinPool's too, after joining the workers: a
  thread that had joined the pool slept on. It takes each slot's mutex
  before notifying, so a waiter between its check and its sleep can't miss
  the wake-up, and works on the pool it started with. Again, or before
  Start, it does nothing; joining a thread twice threw. Its documentation
  says what it doesn't do: stop from a pool task, or from two threads at
  once, run tasks enqueued once it has begun, or have JoinPool wait for it.
- Tests: EnqueueBatch, StopJoinPool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 20:20:29 +02:00

33 lines
1 KiB
C++

//SPDX-License-Identifier: LGPL-3.0-only
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
Configuration cfg;
cfg.path = "./";
cfg.name = "Crafter.Thread";
cfg.outputName = "Crafter.Thread";
cfg.type = ConfigurationType::LibraryStatic;
ApplyStandardArgs(cfg, args);
std::array<fs::path, 2> ifaces = {
"interfaces/Crafter.Thread",
"interfaces/Crafter.Thread-ThreadPool",
};
std::array<fs::path, 1> impls = {
"implementations/Crafter.Thread-ThreadPool",
};
cfg.GetInterfacesAndImplementations(ifaces, impls);
// Tests link this project's static library; wasm builds run no tests.
if (cfg.target.find("wasm") == std::string::npos) {
cfg.AddTest("EnqueueBatch").Dependencies({ &cfg });
cfg.AddTest("StopJoinPool").Dependencies({ &cfg });
}
return cfg;
}