Skip to main content
This topic provides an example of how to clean up a task queue when it’s no longer needed to avoid leaking resources. However, a task queue can’t just immediately be released. It must first be terminated, flushed to ensure that anything enqueued to it has been run, and then released. The terminate call can be set to wait or return immediately. If a callback isn’t waiting, it can optionally be specified to be notified when the termination completely finishes. If there are any manual ports, they must continue to be dispatched until the dispatch function returns.
This example terminates the task queue but doesn’t wait by using the XTaskQueueTerminate wait parameter. The terminate call adds one callback to each port to detect when the queue is emptied. To account for this and any previously enqueued callbacks, dispatch is continually called until it returns false.

Reference API documentation

See also

XTaskQueue library overview Create task queue (example) Dispatch task queue (example) Designing the task queue XTaskQueue
Last modified on August 4, 2026