Files
llvm/lldb/test/API/functionalities/scripted_frame_provider/main.cpp
Med Ismail Bennani c50802cbee Reland "[lldb] Introduce ScriptedFrameProvider for real threads (#161870)" (#170236)
This patch re-lands #161870 with fixes to the previous test failures.

rdar://161834688

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2025-12-02 18:59:40 +00:00

54 lines
1.2 KiB
C++

// Multi-threaded test program for testing frame providers.
#include <condition_variable>
#include <iostream>
#include <mutex>
#include <thread>
std::mutex mtx;
std::condition_variable cv;
int ready_count = 0;
constexpr int NUM_THREADS = 2;
void thread_func(int thread_num) {
std::cout << "Thread " << thread_num << " started\n";
{
std::unique_lock<std::mutex> lock(mtx);
ready_count++;
if (ready_count == NUM_THREADS + 1) {
cv.notify_all();
} else {
cv.wait(lock, [] { return ready_count == NUM_THREADS + 1; });
}
}
std::cout << "Thread " << thread_num << " at breakpoint\n"; // Break here.
}
int main(int argc, char **argv) {
std::thread threads[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; i++) {
threads[i] = std::thread(thread_func, i);
}
{
std::unique_lock<std::mutex> lock(mtx);
ready_count++;
if (ready_count == NUM_THREADS + 1) {
cv.notify_all();
} else {
cv.wait(lock, [] { return ready_count == NUM_THREADS + 1; });
}
}
std::cout << "Main thread at barrier\n";
for (int i = 0; i < NUM_THREADS; i++)
threads[i].join();
std::cout << "All threads completed\n";
return 0;
}