brintos

brintos / llvm-project-archived public Read only

0
0
Text · 919 B · 230aadc Raw
41 lines · cpp
1// This test is intended to create a situation in which a breakpoint will be2// hit in two threads at nearly the same moment.  The expected result is that3// the breakpoint in the second thread will be hit while the breakpoint handler4// in the first thread is trying to stop all threads.5 6#include "pseudo_barrier.h"7#include <thread>8 9pseudo_barrier_t g_barrier;10 11volatile int g_test = 0;12 13void *14thread_func ()15{16    // Wait until both threads are running17    pseudo_barrier_wait(g_barrier);18 19    // Do something20    g_test++;       // Set breakpoint here21 22    // Return23    return NULL;24}25 26int main ()27{28    // Don't let either thread do anything until they're both ready.29    pseudo_barrier_init(g_barrier, 2);30 31    // Create two threads32    std::thread thread_1(thread_func);33    std::thread thread_2(thread_func);34 35    // Wait for the threads to finish36    thread_1.join();37    thread_2.join();38 39    return 0;40}41