Shutdown procedures of Agent using Thread Pool

SNMP++ Version: 3.4.2
Agent++ Version: 4.3.1

I am working on resolving some crashes that are occurring in our Agent during shutdown procedures. Our Agent utilizes the ThreadPool to process requests (#define AGENTPP_USE_THREAD_POOL). We have a particular OID that performs a task with a 2 second timeout. It appears that the main thread processing the shutdown command is deleting the RequestList and Mib objects before the 2 second timeout task running on the ThreadPool has completed. When the timeout expires and the task tries to finish the task and attempts to access the deleted resources and causes the Agent to crash.

I’m looking for guidance on the appropriate way to:
1. Detect if there are threads executing tasks if needed
Can I use mib->get_thread_pool()->is_idle() == false to detect if tasks are currently running in the ThreadPool?
2. Pause/block the main thread until all ThreadPool tasks have gracefully exited
Would the following be appropriate for achieving this?
We have a customer requirement that the Agent will need to exit within 30 seconds of instruction it to shutdown. Is there a way forcibly exit the Threadpool tasks if the call to pMib->get_thread_pool()->join(); takes a significant amount of time to finish?

Your approach above in (1) and (2) is fine. If a thread not timely terminates in the terminate() call, there is no way to “kill” it.