In the original code, vector::erase() would invalidate iterators so we
should move the thread object into the std::async() for the blocking
operation.
Bug: 344250967
Test: atest VtsHalGnssTargetTest
Change-Id: I4cc82131bb070a37cb6ed9dbe9d7cccc7ab5ee89
Before this change, a start() call will wait for previous threads to
finish. However, in ListenerMultiplexer.java in the framework, start(),
stop(), and deliverListener() calls are contending for the same lock.
Therefore, if a waiting start() is holding the lock, while the
almost-finishing thread is also going to hold that lock for calling
deliverListener(), a deadlock will happen.
This CL moves the waiting logic into the new thread of the start() call,
so that start() will return immediately. The new thread will wait for
the old thread to finish, and then start the actual work.
Bug: 299563185
Test: atest CtsLocationGnssTestCases
Change-Id: Ic2993a6d82c24688fa98d26d336c85518c683cf6