1 | #include <chrono> |
2 | #include <thread> |
3 | |
4 | void |
5 | thread_function () |
6 | { |
7 | // Set thread-specific breakpoint here. |
8 | std::this_thread::sleep_for(rtime: std::chrono::milliseconds(20)); |
9 | // On Windows, a sleep_for of less than about 16 ms effectively calls |
10 | // Sleep(0). The MS standard thread implementation uses a system thread |
11 | // pool, which can deadlock on a Sleep(0), hanging not only the secondary |
12 | // thread but the entire test. I increased the delay to 20 ms to ensure |
13 | // Sleep is called with a delay greater than 0. The deadlock potential |
14 | // is described here: |
15 | // https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleep#remarks |
16 | } |
17 | |
18 | int |
19 | main () |
20 | { |
21 | // Set main breakpoint here. |
22 | |
23 | #ifdef __APPLE__ |
24 | pthread_setname_np("main-thread" ); |
25 | #endif |
26 | |
27 | std::thread t(thread_function); |
28 | t.join(); |
29 | |
30 | thread_function(); |
31 | return 0; |
32 | } |
33 | |