[clang][deps] Ensure the service outlives async module compiles (#181772)
This PR fixes a race condition discovered by thread sanitizer in the
asynchronous dependency scanner implementaion.
The implementation assumed that whenever a new thread is spawned to
compile a module, the primary scanning thread must wait for it to finish
to read the PCM it produces. This is not true - it's possible for the
implicit build on the primary thread to decide to compile the same
module too, leaving the asynchronous thread running without any kind of
synchronization. This means the TU scan may return, the service may get
destroyed, but the asynchronous thread continues running with the VFS
caches and module cache implementation destroyed, leading to crashes.
This PR fixes this by awaiting all asynchronous threads at the end of a
TU scan.