Which mechanism ensures a TTask terminates during a timeout in RAD Studio?
20K reputation · 05 Mar 2025, 08:02 UTC
The Parallel Programming Library (PPL) in RAD Studio provides the ITask interface for background execution. While ITask.Cancel allows for the signaling of a task to stop, the worker thread must manually poll for this state to exit gracefully.
A challenge arises when implementing strict timeouts for asynchronous operations. Because ITask does not include a native timeout property, developers must coordinate external triggers, such as TTimer or TEvent, to initiate the cancellation process.
Given that ITask.Cancel does not forcibly terminate the thread, there is uncertainty regarding the most reliable way to ensure a blocked task actually yields control when a timeout occurs without risking resource exhaustion in the thread pool.
- What is the recommended pattern for integrating a timeout trigger with
ITaskpolling? - Does the PPL provide a way to force termination if a task becomes unresponsive to cancellation signals?