1//===-- thread_inferior.cpp -----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <atomic>
10#include <chrono>
11#include <string>
12#include <thread>
13#include <vector>
14
15int main(int argc, char* argv[]) {
16 int thread_count = 2;
17 if (argc > 1) {
18 thread_count = std::stoi(str: argv[1], idx: nullptr, base: 10);
19 }
20
21 std::atomic<bool> delay(true);
22 std::vector<std::thread> threads;
23 for (int i = 0; i < thread_count; i++) {
24 threads.push_back(x: std::thread([&delay] {
25 while (delay.load())
26 std::this_thread::sleep_for(rtime: std::chrono::seconds(1));
27 }));
28 }
29
30 // Cause a break.
31 volatile char *p = nullptr;
32 *p = 'a';
33
34 delay.store(i: false);
35 for (std::thread& t : threads) {
36 t.join();
37 }
38
39 return 0;
40}
41

source code of lldb/unittests/tools/lldb-server/inferior/thread_inferior.cpp