[lldb] Stabilize threaded windows lldb-server tests
The tests enabled in 9e699595 are not passing reliably -- sometimes they
report seeing fewer threads than expected.
Based on my (limited) research, this is not a lldb bug, but simply a
consequence of the operating system reporting their presence
asynchronously -- they're reported when they are scheduled to run (or
something similar), and not at the time of the CreateThread call.
To fix this, I add some additional synchronization to the test inferior,
which makes sure that the created thread is alive before continuing to
do other things.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <errno.h>
|
||||
#include <future>
|
||||
#include <inttypes.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -158,7 +159,8 @@ static void hello() {
|
||||
printf("hello, world\n");
|
||||
}
|
||||
|
||||
static void *thread_func(void *arg) {
|
||||
static void *thread_func(std::promise<void> ready) {
|
||||
ready.set_value();
|
||||
static std::atomic<int> s_thread_index(1);
|
||||
const int this_thread_index = s_thread_index++;
|
||||
if (g_print_thread_ids) {
|
||||
@@ -328,7 +330,10 @@ int main(int argc, char **argv) {
|
||||
_exit(0);
|
||||
#endif
|
||||
} else if (consume_front(arg, "thread:new")) {
|
||||
threads.push_back(std::thread(thread_func, nullptr));
|
||||
std::promise<void> promise;
|
||||
std::future<void> ready = promise.get_future();
|
||||
threads.push_back(std::thread(thread_func, std::move(promise)));
|
||||
ready.wait();
|
||||
} else if (consume_front(arg, "thread:print-ids")) {
|
||||
// Turn on thread id announcing.
|
||||
g_print_thread_ids = true;
|
||||
|
||||
Reference in New Issue
Block a user