Atomic predicate replacement limits during module reload in SWI-Prolog 8.5+
0 reputation · 14 Apr 2026, 18:10 UTC
Context
SWI-Prolog 8.5 introduced use_module/2 with the reload(true) option, which replaces predicate definitions atomically within a single thread. This capability is documented as a mechanism for updating logic without restarting the runtime.
Constraint
The documentation and ISO/IEC 13211 do not specify behavior when multiple threads concurrently execute predicates that are being reloaded. Existing clause references in running threads may become invalid, and no standard synchronization primitive coordinates the transition across threads.
Goal
Determine whether a small multi-threaded Prolog application can migrate its predicate definitions using reload(true) without exposing callers to intermediate states or existence_error exceptions.
Questions
- What guarantees, if any, does SWI-Prolog 8.5+ provide about predicate visibility for threads that entered a predicate before
reload(true)completes? - Is there a documented pattern—such as thread-local predicate wrappers or a double-buffered module scheme—that achieves atomic cross-thread updates without external coordination?