Skip to content

Commit 9611282

Browse files
committed
[lldb] Stabilize threaded windows lldb-server tests
The tests enabled in 9e69959 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.
1 parent 96000f5 commit 9611282

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lldb/test/API/tools/lldb-server/main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <cstdlib>
44
#include <cstring>
55
#include <errno.h>
6+
#include <future>
67
#include <inttypes.h>
78
#include <memory>
89
#include <mutex>
@@ -158,7 +159,8 @@ static void hello() {
158159
printf("hello, world\n");
159160
}
160161

161-
static void *thread_func(void *arg) {
162+
static void *thread_func(std::promise<void> ready) {
163+
ready.set_value();
162164
static std::atomic<int> s_thread_index(1);
163165
const int this_thread_index = s_thread_index++;
164166
if (g_print_thread_ids) {
@@ -328,7 +330,10 @@ int main(int argc, char **argv) {
328330
_exit(0);
329331
#endif
330332
} else if (consume_front(arg, "thread:new")) {
331-
threads.push_back(std::thread(thread_func, nullptr));
333+
std::promise<void> promise;
334+
std::future<void> ready = promise.get_future();
335+
threads.push_back(std::thread(thread_func, std::move(promise)));
336+
ready.wait();
332337
} else if (consume_front(arg, "thread:print-ids")) {
333338
// Turn on thread id announcing.
334339
g_print_thread_ids = true;

0 commit comments

Comments
 (0)