Wait for threads to finish unregistering
There was a race where Thread::join would return before the thread was
unregistered. This caused a problem with Daemons.stop since the thread
list could get deleted before the daemon thread was removed from list_.
This caused occasional "Request to unregister unattached thread"
errors and warnings.
The fix is to wait until threads finish registering before destroying
the thread list. The only threads which can be unregistering at this
point are the daemons we stopped earlier during the runtime shutdown
process. The issue is that thread join finishes before we remove the
thread from the thread list.
Also some cleanup.
4 files changed