Parma Polyhedra Library requirements
Computational-weight and cooperative-abandonment interfaces

Computational-weight and cooperative-abandonment interfaces

UID:
VERSION:
CLASSIFICATION:
PREFIX:
Type
Level
MID
UID
REFS
Title
Statement
Rationale
Comment
BIBLIOGRAPHY
STATUS
COMPONENT
APPLICABILITY
VERIFICATION_METHODS
VERIFICATION_CRITERIA
SOURCE
LANGUAGE
VISIBILITY
INTERFACE
SW_SPEC
1
PPL-SPEC-000863
Computational-weight value and current-state binding

Weightwatch_Traits::Threshold and Delta shall denote unsigned long long. The computational-weight counter shall initially be zero and get() shall return a const reference to its current counter, without copying or allocating. The returned reference shall observe later admitted serial updates. In a thread-safe configuration, that counter/reference shall belong to the calling thread and shall not be used after that thread exits or from another thread. The checking slot shall initially be null and retain the watcher-owned protocol in 🔗 6. Published checking function and empty-queue transitions. In a thread-safe build the counter, checking slot and Threshold_Watcher<Weightwatch_Traits> queue shall all belong to the calling thread. Each watcher and its borrowed notification bindings shall be used and destroyed in that thread before it exits. Other threads may independently compute, register, cancel and dispatch their own budgets.

In a thread-safe build, the checking slot shall be a function-pointer proxy: assignment, conversion to void (*)(), invocation and independent copied snapshots shall retain their ordinary meanings. Assigning a local snapshot shall not change the live slot. A live-slot assignment shall not alter another thread's hook or the signal-notification gate. Direct field-address/type-trait compatibility with former raw/shared fields is not required; clients shall be rebuilt with matching library headers. Library and clients shall agree on the bool/function-pointer atomic capability selection; a compatible C++ ABI alone shall not permit mixing dispatcher modes. Clients shall not overwrite their checker while its queue contains events.

At an owner checkpoint that selects pending atomic-watchdog work, that work shall be published before checking computational thresholds. A notification arriving after the checkpoint's dispatch snapshot may be processed at the next checkpoint. With always-lock-free notification and function-pointer atomics, unexpired timers shall not install an extra checkpoint callback. Otherwise, ordinary owner code shall use a deferred per-thread hook; the signal action shall not access thread-local objects or call a potentially locking atomic operation.

The budget counter, pending events and checking hook must have the same owner; independent thread budgets must not alter or dispatch one another.

APPROVED
RUNTIME
IF_CPP
Test, Analysis, Inspection

Check configured slot types, reference identity, serial updates and copied hook snapshots; inspect initial/thread-local declarations and per-queue ownership. Check simultaneous thread budgets and cancellation without serializing independent PPL work. Exercise both admitted function-pointer dispatch and a coherently rebuilt deferred fallback, including cancellation, wrong-thread checkpoints and real timer delivery.

src/globals_defs.hh; src/globals_inlines.hh; src/globals.cc; src/thread_safe.hh; tests/weightwatchspec1.cc; tests/weightwatchlegacy1.cc; tests/atomicwatchdogspec1.cc; tests/Polyhedron/weightwatch1.cc.

CPP
Internal

Defining C++ headers: globals_defs.hh and globals_inlines.hh. Names belong to Parma_Polyhedra_Library unless a macro is shown. Computational-weight watchers retain 🔗 12. Watcher notification lifetimes and exclusive use.

struct Weightwatch_Traits {
  using Threshold = unsigned long long;
  using Delta = unsigned long long;
  static constexpr bool thread_local_queue = true;
  static const Threshold& get();
  static Threshold weight; // Thread-local in a thread-safe build.
#ifdef PPL_THREAD_SAFE
  static Implementation::Watchdog::Checkpoint_Hook check_function; // Thread-local.
#else // !defined(PPL_THREAD_SAFE)
  static void (*check_function)();
#endif // !defined(PPL_THREAD_SAFE)
};
SW_SPEC
2
PPL-SPEC-000864
PPL-SPEC-000864
Exact scaled-weight conversion and representability

compute_delta(u, s) shall return the exact integer u2s when that result is representable in Delta. For u == 0 it shall return zero for every unsigned scale. For nonzero u, an excessive shift or a scaled result larger than Delta's maximum shall throw std::invalid_argument rather than wrap. The function shall not change the current counter or checking slot. Returning a zero delta shall not imply that an already reached watcher threshold is admissible under 🔗 4. Threshold conversion and already-reached rejection.

Scaling must distinguish exact increments from an unrepresentable user request independently of watcher registration.

APPROVED
RUNTIME
IF_CPP
Test, Analysis, Inspection

Compare against arbitrary-precision shifts over zero, all bit boundaries and maximum inputs; reject each excessive nonzero scale and overflow and preserve backend state.

src/globals_defs.hh; src/globals_inlines.hh; src/globals.cc; src/thread_safe.hh; tests/weightwatchspec1.cc; tests/weightwatchlegacy1.cc; tests/Polyhedron/weightwatch1.cc.

CPP
Internal

Defining C++ headers: globals_defs.hh and globals_inlines.hh. Names belong to Parma_Polyhedra_Library unless a macro is shown. Computational-weight watchers retain 🔗 12. Watcher notification lifetimes and exclusive use.

static Delta compute_delta(unsigned long unscaled, unsigned scale);
SW_SPEC
3
PPL-SPEC-000865
PPL-SPEC-000865
Absolute threshold formation and modular aliases

from_delta(out, d) shall assign the unsigned modular sum of the current weight and the supplied delta to out. It shall admit out aliasing the delta object or the current counter and evaluate the sum from their values before assignment. It shall neither register an event nor invoke a notification. This arithmetic conversion shall not itself validate whether the result is future under 🔗 4. Strict circular ordering of computational weights; watcher construction shall perform that check under 🔗 4. Threshold conversion and already-reached rejection.

Threshold formation uses defined unsigned wraparound and must retain legitimate input/output aliases.

APPROVED
RUNTIME
IF_CPP
Test, Analysis, Inspection

Compare ordinary and wrapping sums against exact-integer modular arithmetic; cover independent output, output/delta alias, output/current alias and all-three aliases without dispatch.

src/globals_defs.hh; src/globals_inlines.hh; src/globals.cc; src/thread_safe.hh; tests/weightwatchspec1.cc; tests/weightwatchlegacy1.cc; tests/Polyhedron/weightwatch1.cc.

CPP
Internal

Defining C++ headers: globals_defs.hh and globals_inlines.hh. Names belong to Parma_Polyhedra_Library unless a macro is shown. Computational-weight watchers retain 🔗 12. Watcher notification lifetimes and exclusive use.

static void from_delta(Threshold& threshold, const Delta& delta);
SW_SPEC
4
PPL-SPEC-000866
PPL-SPEC-000866
Strict circular ordering of computational weights

Let N be the number of value bits in Threshold and let d be the unsigned modular difference of b and a, in [0, 2N). less_than(a, b) shall return true exactly when 0 < d < 2N − 1. Equal weights shall compare false; values separated by exactly a half-range shall not acquire an arbitrary orientation. An admitted queue/check history shall keep its current and pending thresholds within a common circular interval shorter than a half-range so that this comparison gives the coherent strict ordering required by 🔗 1. Generic threshold-watcher traits and admitted value protocol. The function shall not allocate, notify or change its operands/backend state.

A modular counter needs a strict unambiguous local order, including equality, to support duplicate deadlines and exact-threshold dispatch.

APPROVED
RUNTIME
IF_CPP
Test, Analysis, Inspection

Compare equal, unequal, wrapping and half-range boundaries against an independent modular-distance oracle; verify duplicate future deadlines, zero-delta rejection and exact-deadline dispatch through the generic watcher.

src/globals_defs.hh; src/globals_inlines.hh; src/globals.cc; src/thread_safe.hh; tests/weightwatchspec1.cc; tests/weightwatchlegacy1.cc; tests/Polyhedron/weightwatch1.cc.

CPP
Internal

Defining C++ headers: globals_defs.hh and globals_inlines.hh. Names belong to Parma_Polyhedra_Library unless a macro is shown. Computational-weight watchers retain 🔗 12. Watcher notification lifetimes and exclusive use.

static bool less_than(const Threshold& a, const Threshold& b);
SW_SPEC
5
PPL-SPEC-000867
Computational-weight instrumentation outside profiling mode

In the normal computational-weight configuration (PPL_PROFILE_ADD_WEIGHT == 0), WEIGHT_BEGIN() shall not change the counter. Outside the assertion suppression of 🔗 6. Assertion-scope instrumentation suppression, WEIGHT_ADD(d) shall add the value of its supplied expression and WEIGHT_ADD_MUL(d, f) shall add the product of the values of both supplied expressions. Each supplied expression shall be evaluated once; the caller shall supply arithmetic expressions with defined evaluation, conversion and multiplication. Accumulation shall retain unsigned modular arithmetic and shall not itself dispatch pending notifications. The same admitted expressions shall have the same mathematical effect in assertion and nonassertion builds.

An explicitly enabled release-build Weight_Profiler configuration shall follow 🔗 1. Optional profiler selection and instrumentation protocol through 🔗 4. Profiler reports, lifetime output and startup calibration.

The counter must reflect instrumented arithmetic independently of ordinary build diagnostics, while the optional profiler has a separate role.

APPROVED
RUNTIME
IF_CPP
Test, Analysis, Inspection

Check direct and product increments against modular integer arithmetic, compound expressions, argument evaluation counts, wrapping boundaries, no implicit dispatch and assertion suppression in both build modes.

src/globals_defs.hh; src/globals_inlines.hh; src/globals.cc; src/thread_safe.hh; tests/weightwatchspec1.cc; tests/weightwatchlegacy1.cc; tests/Polyhedron/weightwatch1.cc; tests/MIP_Problem/mipproblem2.cc.

CPP
Internal

Defining C++ headers: globals_defs.hh and globals_inlines.hh. Names belong to Parma_Polyhedra_Library unless a macro is shown. Computational-weight watchers retain 🔗 12. Watcher notification lifetimes and exclusive use.

WEIGHT_BEGIN();
WEIGHT_ADD(delta);
WEIGHT_ADD_MUL(delta, factor);
SW_SPEC
6
PPL-SPEC-000868

In builds without NDEBUG, In_Assert shall maintain a nesting count in the calling thread (or the sole configured global context). Its construction shall enter assertion evaluation and destruction shall leave it. asserting() shall be true exactly while that count is nonzero. Balanced nested scopes, including exception unwinding, shall restore the previous state. During such a scope, computational-weight increment macros shall neither increment the counter nor evaluate their increment expressions, and maybe_abandon() shall return without checking thresholds or caller-owned requests. Clients shall retain properly nested, noncopied guard lifetimes. In_Assert shall not be required to exist in builds with NDEBUG.

Diagnostic assertions must not add computational work or trigger cooperative interruption themselves.

APPROVED
RUNTIME
IF_CPP
Test, Analysis, Inspection

Check nested scopes, suppressed expression side effects, held callbacks/requests and restoration after normal exit and exception unwinding; inspect configured thread-local storage.

src/globals_defs.hh; src/globals_inlines.hh; src/globals.cc; src/thread_safe.hh; tests/weightwatchspec1.cc; tests/weightwatchlegacy1.cc; tests/Polyhedron/weightwatch1.cc.

CPP
Internal

Defining C++ headers: globals_defs.hh and globals_inlines.hh. Names belong to Parma_Polyhedra_Library unless a macro is shown. Computational-weight watchers retain 🔗 12. Watcher notification lifetimes and exclusive use.

#ifndef NDEBUG
class In_Assert {
public:
  In_Assert();
  ~In_Assert();
  static bool asserting();
};
#endif
SW_SPEC
7
PPL-SPEC-000869
Caller-owned abandonment request and exception object

Throwable shall provide a const virtual throw_me() action and virtual destruction. abandon_expensive_computations shall initially be null and shall retain a borrowed pointer to a caller-owned live Throwable. The client shall keep the request object alive through all admitted reads/actions, publish it under the configured synchronization and execution-context rules, and clear/replace the slot before ending that lifetime. The library shall not own/delete the object or clear a request after invoking it. In a thread-safe configuration the request slot shall be thread-local and atomic; the ordinary configuration shall use its declared volatile pointer protocol. Cross-thread publication shall target the intended live slot under the caller's synchronization; thread-local storage shall not turn a write to another thread's own slot into a request for the computing thread.

Cooperative interruption borrows a client-supplied exception mechanism with explicit persistence and lifetime ownership.

APPROVED
RUNTIME
IF_CPP
Test, Analysis, Inspection

Check derived const dispatch, virtual destruction, retained object lifetime and request identity through normal-returning and throwing actions; inspect atomic/thread-local versus volatile declarations.

src/globals_defs.hh; src/globals_inlines.hh; src/globals.cc; src/thread_safe.hh; tests/weightwatchspec1.cc; tests/weightwatchlegacy1.cc; tests/Polyhedron/weightwatch1.cc.

CPP
Public

Defining C++ headers: globals_defs.hh and globals_inlines.hh. Names belong to Parma_Polyhedra_Library unless a macro is shown. Computational-weight watchers retain 🔗 12. Watcher notification lifetimes and exclusive use.

class Throwable {
public:
  virtual void throw_me() const = 0;
  virtual ~Throwable();
};
extern abandon_type abandon_expensive_computations;
SW_SPEC
8
PPL-SPEC-000870
Cooperative abandonment checkpoint ordering and propagation

Outside 🔗 6. Assertion-scope instrumentation suppression, maybe_abandon() shall first invoke the nonnull computational-weight checking hook. If that action returns, it shall select the current registration-scoped request in a thread-safe build 🔗 5. Interruptible thread registration and request lifetime, if one is present, or read the current caller-owned abandonment slot. It shall invoke the selected nonnull object's const throw_me() action. The read shall observe admitted serial request changes made by the hook. A throwing hook shall propagate its exception and prevent the later action for that invocation. A throwing request action shall likewise propagate. Neither path shall clear a request, undo callback effects or take ownership of its object. A null hook/request shall be skipped. The checkpoint shall not promise a fixed elapsed-time interruption bound.

Threshold handling precedes the current client request, and interruption effects must remain visible for retry or explicit cancellation.

APPROVED
RUNTIME
IF_CPP
Test, Analysis, Inspection

Use exact event logs for null/present hook/request combinations, hook publication/clearing of requests, normal/throwing actions, persistent requests and assertion suppression; verify propagated exception identity and action order.

src/globals_defs.hh; src/globals_inlines.hh; src/globals.cc; src/make_threadable.cc; tests/Polyhedron/threadsafe2.cc; src/thread_safe.hh; tests/weightwatchspec1.cc; tests/weightwatchlegacy1.cc; tests/Polyhedron/weightwatch1.cc; tests/MIP_Problem/mipproblem2.cc.

CPP
Internal

Defining C++ headers: globals_defs.hh and globals_inlines.hh. Names belong to Parma_Polyhedra_Library unless a macro is shown. Computational-weight watchers retain 🔗 12. Watcher notification lifetimes and exclusive use.

void maybe_abandon();