- Type: (A) Bug / Feature request (extension point); (B) Bug (audio dropout)
- TE version: pinned commit 38d5a27 (develop, 2026-10-14). The affected files have not changed on develop since then (checked 2026-12-04).
- Affected code:
modules/tracktion_graph/utilities/tracktion_LockFreeObject.h:LockFreeObject::retainRealTime/pushNonRealTimemodules/tracktion_graph/tracktion_graph/tracktion_LockFreeMultiThreadedNodePlayer.{h,cpp}:ThreadPool,createThreads(),process(),prepareToPlay(),postNewGraph()modules/tracktion_engine/playback/graph/tracktion_TracktionNodePlayer.h,modules/tracktion_engine/playback/tracktion_EditPlaybackContext.{h,cpp}(forwarding only)
Problem
(A) When the audio thread swaps in a pending graph, the old graph is moved into pendingObjectStorage:
if (auto newObject = pendingObject.exchange (nullptr))
std::swap (objectStorage, *newObject);
It is handed back only by the next pushNonRealTime(), which postNewGraph() then destroys after waitForThreadsToQuiesce(), or it is destroyed by clear(). Until then, the retired graph keeps everything it owns alive: plugin instances, input nodes and file readers. After the last live edit, nothing frees it. In our app, plugins run in an out-of-process host, and the retired graph kept host slots reserved indefinitely. In one recorded run, the newest graph had been playing for 4 seconds and two slots were still reserved.
(B) Every setNode() goes through prepareToPlay(), which calls createThreads(). That function takes processMutex even when the pool already runs the requested number of threads:
void LockFreeMultiThreadedNodePlayer::createThreads()
{
const std::scoped_lock<RealTimeSpinLock> sl (processMutex);
threadPool->createThreads (numThreadsToUse.load(), audioWorkgroup);
}
process() only try-locks that mutex and skips the whole block if it fails:
const std::unique_lock<RealTimeSpinLock> l (processMutex, std::try_to_lock);
// If this fails, it's because the clearNode function is being called
if (! l.owns_lock())
return -1;
Under load, this produces one silent block per live graph change.
How to reproduce
(A) Steps:
- Publish two graphs with
setNode(). - Process a few blocks so the second graph is swapped in.
- Make no further publication.
The first graph’s destructor never runs. To check this, give a node a std::shared_ptr sentinel and observe it through a std::weak_ptr. The destructor only runs after a third setNode() or after clearNode().
(B) This is condensed from our test:
- On one thread, run
LockFreeMultiThreadedNodePlayer::process()in a loop with a constant-level graph, using 0 or 2 pool threads. - On another thread, call
setNode()repeatedly with equivalent graphs. - Check every output block for the expected level.
Some blocks come back silent (process() returned -1) while setNode() is inside createThreads(). Without the patch, 3–8 of 32 parallel runs were affected. With it, 92 of 92 passed.
Proposed patch
(A) Add a non-blocking reclaim of the retired graph that runs on the control thread:
--- a/modules/tracktion_graph/utilities/tracktion_LockFreeObject.h
+++ b/modules/tracktion_graph/utilities/tracktion_LockFreeObject.h
+ /** Takes only a retired object, never a pending publication.
+ Call on the same non-real-time control thread as push/clear. Does not
+ wait for real-time access. canRelease receives the retired pointer and
+ must non-blockingly confirm that external readers can no longer use it.
+ The returned owner is destroyed by the caller, outside the lock.
+ */
+ template<typename CanRelease>
+ [[nodiscard]] std::unique_ptr<ObjectType> tryTakeRetiredNonRealTime (CanRelease&& canRelease)
+ {
+ const std::unique_lock<RealTimeSpinLock> lock (pushingObjectMutex, std::try_to_lock);
+ if (! lock.owns_lock() || pendingObject.load() != nullptr || ! pendingObjectStorage
+ || ! canRelease (pendingObjectStorage.get()))
+ return {};
+
+ return std::move (pendingObjectStorage);
+ }
+
/** Retains the object for use in a real time thread.
--- a/modules/tracktion_graph/tracktion_graph/tracktion_LockFreeMultiThreadedNodePlayer.h
+++ b/modules/tracktion_graph/tracktion_graph/tracktion_LockFreeMultiThreadedNodePlayer.h
@@ class ThreadPool
+ /** Non-blocking retirement check. The caller must already exclude
+ republishing this node. The sequentially-consistent pointer
+ load followed by the reader count pairs with process(): an old
+ reader is counted, or a newly entering reader obtains the new node.
+ */
+ bool canReclaimRetiredNode (const LockFreeMultiThreadedNodePlayer::PreparedNode* retired) const
+ {
+ return currentPreparedNode.load() != retired && numActiveProcessCalls.load() == 0;
+ }
+
/** Waits until no pool threads are inside a process() call.
@@
void clearNode();
+
+ /** Destroys the last retired graph if no audio/pool reader retains
+ it. Retry later if busy. Call on the same control thread as setNode,
+ prepareToPlay and clearNode, never from an audio or pool thread.
+ */
+ bool reclaimRetiredGraph();
--- a/modules/tracktion_graph/tracktion_graph/tracktion_LockFreeMultiThreadedNodePlayer.cpp
+++ b/modules/tracktion_graph/tracktion_graph/tracktion_LockFreeMultiThreadedNodePlayer.cpp
+bool LockFreeMultiThreadedNodePlayer::reclaimRetiredGraph()
+{
+ auto retired = preparedNodeObject.tryTakeRetiredNonRealTime ([this] (auto* node)
+ {
+ return threadPool->canReclaimRetiredNode (node);
+ });
+ // Only the retired owner is destroyed, after releasing the publication
+ // lock. Current/pending graphs and their preparation pointers stay intact.
+ return retired != nullptr;
+}
+
void LockFreeMultiThreadedNodePlayer::clearNode()
The same method is forwarded through three layers:
TracktionNodePlayer::reclaimRetiredGraph()- the internal
EditPlaybackContext::NodePlaybackContext EditPlaybackContext::reclaimRetiredGraph(), which asserts that it runs on the message thread
(B) Take the lock only when the thread count actually changes:
--- a/modules/tracktion_graph/tracktion_graph/tracktion_LockFreeMultiThreadedNodePlayer.h
+++ b/modules/tracktion_graph/tracktion_graph/tracktion_LockFreeMultiThreadedNodePlayer.h
std::atomic<size_t> numThreadsToUse { std::max ((size_t) 0, (size_t) std::thread::hardware_concurrency() - 1) };
+ std::atomic<size_t> threadsCreated { 0 }; // threads the pool runs, set under processMutex
--- a/modules/tracktion_graph/tracktion_graph/tracktion_LockFreeMultiThreadedNodePlayer.cpp
+++ b/modules/tracktion_graph/tracktion_graph/tracktion_LockFreeMultiThreadedNodePlayer.cpp
void LockFreeMultiThreadedNodePlayer::clearThreads()
{
const std::scoped_lock<RealTimeSpinLock> sl (processMutex);
threadPool->clearThreads();
+ threadsCreated.store (0, std::memory_order_release);
}
void LockFreeMultiThreadedNodePlayer::createThreads()
{
+ // Nothing to create, so the audio thread must not lose its block.
+ if (threadsCreated.load (std::memory_order_acquire) == numThreadsToUse.load())
+ return;
+
const std::scoped_lock<RealTimeSpinLock> sl (processMutex);
threadPool->createThreads (numThreadsToUse.load(), audioWorkgroup);
+ threadsCreated.store (numThreadsToUse.load(), std::memory_order_release);
}
How the patch works
(A) We call reclaimRetiredGraph() from an existing message-thread timer. Each call makes one try-lock attempt on pushingObjectMutex. In process(), the audio thread holds that lock (through ScopedRealTimeAccess) across the swap-in and setCurrentNode(). A successful try-lock therefore means no swap is in progress. A graph that is still pending is never taken.
The retired graph is released only when both of these hold:
- the pool’s
currentPreparedNodeno longer points to it - the existing
numActiveProcessCallscounter is zero
These are the same seq-cst guarantees that waitForThreadsToQuiesce() relies on, but checked without waiting. If either check fails, the call returns false and the caller retries later. Destruction happens on the control thread, outside the lock. Nothing is added to the audio path.
Risk: freeing retired graphs sooner makes existing lifetime bugs in graph nodes show up sooner. We hit one in input nodes (posted separately).
Alternatives:
- have
pushNonRealTimereturn retired objects through a release queue that TE drains itself - reclaim automatically in
EditPlaybackContexton a timer
(B) threadsCreated is only written under processMutex. The fast path skips the lock when it would not change anything. setNumThreads() still goes through clearThreads(), which resets the counter, and then createThreads().
Risk: if numThreadsToUse is 0 from the start, createThreads (0, …) is never called. That looked harmless in our tests, which covered 0 and 2 threads, but please check it against the pool implementations.
Tests on our side
- A unit test on
LockFreeObjectchecks that the reclaim:- never takes a pending publication
- never waits while the real-time side holds access
- honours a rejecting
canRelease
- 64 graph swaps with 0 and 2 pool threads, with and without pooled memory: the old graph is freed on the control thread, the current graph survives, and no block comes back silent or at the wrong level.