1*99451b44SJordan Rupprecht //===-- main.cpp ------------------------------------------------*- C++ -*-===//
2*99451b44SJordan Rupprecht //
3*99451b44SJordan Rupprecht // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*99451b44SJordan Rupprecht // See https://llvm.org/LICENSE.txt for license information.
5*99451b44SJordan Rupprecht // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*99451b44SJordan Rupprecht //
7*99451b44SJordan Rupprecht //===----------------------------------------------------------------------===//
8*99451b44SJordan Rupprecht 
9*99451b44SJordan Rupprecht // This test is intended to create a situation in which a breakpoint will be
10*99451b44SJordan Rupprecht // hit in two threads at nearly the same moment.  The expected result is that
11*99451b44SJordan Rupprecht // the breakpoint in the second thread will be hit while the breakpoint handler
12*99451b44SJordan Rupprecht // in the first thread is trying to stop all threads.
13*99451b44SJordan Rupprecht 
14*99451b44SJordan Rupprecht #include "pseudo_barrier.h"
15*99451b44SJordan Rupprecht #include <thread>
16*99451b44SJordan Rupprecht 
17*99451b44SJordan Rupprecht pseudo_barrier_t g_barrier;
18*99451b44SJordan Rupprecht 
19*99451b44SJordan Rupprecht volatile int g_test = 0;
20*99451b44SJordan Rupprecht 
21*99451b44SJordan Rupprecht void *
22*99451b44SJordan Rupprecht thread_func ()
23*99451b44SJordan Rupprecht {
24*99451b44SJordan Rupprecht     // Wait until both threads are running
25*99451b44SJordan Rupprecht     pseudo_barrier_wait(g_barrier);
26*99451b44SJordan Rupprecht 
27*99451b44SJordan Rupprecht     // Do something
28*99451b44SJordan Rupprecht     g_test++;       // Set breakpoint here
29*99451b44SJordan Rupprecht 
30*99451b44SJordan Rupprecht     // Return
31*99451b44SJordan Rupprecht     return NULL;
32*99451b44SJordan Rupprecht }
33*99451b44SJordan Rupprecht 
34*99451b44SJordan Rupprecht int main ()
35*99451b44SJordan Rupprecht {
36*99451b44SJordan Rupprecht     // Don't let either thread do anything until they're both ready.
37*99451b44SJordan Rupprecht     pseudo_barrier_init(g_barrier, 2);
38*99451b44SJordan Rupprecht 
39*99451b44SJordan Rupprecht     // Create two threads
40*99451b44SJordan Rupprecht     std::thread thread_1(thread_func);
41*99451b44SJordan Rupprecht     std::thread thread_2(thread_func);
42*99451b44SJordan Rupprecht 
43*99451b44SJordan Rupprecht     // Wait for the threads to finish
44*99451b44SJordan Rupprecht     thread_1.join();
45*99451b44SJordan Rupprecht     thread_2.join();
46*99451b44SJordan Rupprecht 
47*99451b44SJordan Rupprecht     return 0;
48*99451b44SJordan Rupprecht }
49