|
BDE 4.39.x Production Release
|
Provide guard to verify work completion within a set duration.
Provide guard to verify work completion within a set duration.
This component provides a thread-enabled guard, bslmt::TimedCompletionGuard, which invokes a handler displaying provided diagnostic text if the guard is not destroyed or released within a specified duration.
This section illustrates intended use of this component.
In the following example a bslmt::TimedCompletionGuard is used as a testing aid verify work done on a thread completes in a specified amount of time. The work is done in two parts, but the actual tasks are not relevant to the example and is elided.
First, define the two thread functions containing the work to be done:
Next, we create and configure tcg to allow both parts of the work one second to complete and verify the guard was started successfully:
Then, we create a thread to execute the first part of the work, and join the created thread when the work completes:
Next, we update the text displayed if the duration should expire to reflect the second portion of the work:
Now, we use a thread to execute the second part of the work:
Finally, we release the guard: