Manifold 3.0
Robust geometry
Loading...
Searching...
No Matches
ExecutionContext Class Reference

Observe and control a long-running Manifold evaluation. More...

#include <common.h>

Public Member Functions

 ExecutionContext (const ExecutionContext &)
 ExecutionContext (ExecutionContext &&) noexcept
ExecutionContext & operator= (const ExecutionContext &)
ExecutionContext & operator= (ExecutionContext &&) noexcept
void Cancel ()
 Request cancellation. Can be called from any thread. Idempotent.
bool Cancelled () const
 Has cancellation been requested?
double Progress () const

Public Attributes

std::shared_ptr< Impl > impl_

Detailed Description

Observe and control a long-running Manifold evaluation.

Pass to Manifold::Status(ctx) to observe progress and optionally request cancellation of the evaluation. Safe to read/write from any thread.

Copyable and movable: copies share the same underlying state via a shared_ptr, so one thread can evaluate while another holds a copy and observes Progress() or calls Cancel(). Use a separate context per evaluation; passing the same context (or a copy of it) to two concurrent Status(ctx) calls produces meaningless progress values because both calls reset and mutate the same counters.

Cancellation is permanent for a Manifold: once requested and detected, the Manifold's status becomes Error::Cancelled and stays Cancelled. To retry, construct a new Manifold. A context, however, is reusable: each Status(ctx) call resets the progress counters, but it does NOT clear the cancel flag — once Cancel() has been called on a context, every subsequent evaluation with that context (or any copy of it) will short-circuit to Error::Cancelled. Construct a fresh context to make a new evaluation cancellable independently.

Cancellation granularity is currently per-boolean-operation; a single large boolean may run to completion before the flag is checked again. This may improve in future versions.

Example: cancel from an observer thread.

Manifold big = Manifold::BatchBoolean(items, OpType::Add);
ExecutionContext ctx;
std::thread eval([&] {
if (big.Status(ctx) == Manifold::Error::Cancelled) {
// evaluation was cancelled
}
});
// ...later, from the UI thread:
ctx.Cancel();
eval.join();
void Cancel()
Request cancellation. Can be called from any thread. Idempotent.
This library's internal representation of an oriented, 2-manifold, triangle mesh - a simple boundary-...
Definition manifold.h:302
static Manifold BatchBoolean(const std::vector< Manifold > &manifolds, OpType op)
Definition manifold.cpp:838
Error Status() const
Definition manifold.cpp:264

Member Function Documentation

◆ Progress()

double Progress ( ) const

Normalized progress in [0, 1]. Returns 0 before any work has been scheduled. Monotonically increases during evaluation.