1 //===-- main.cpp ------------------------------------------------*- C++ -*-===//
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 "pseudo_barrier.h"
10 #include <cstdio>
11 #include <thread>
12 
13 volatile uint32_t g_val = 0;
14 pseudo_barrier_t g_barrier;
15 
16 void thread_func() {
17   pseudo_barrier_wait(g_barrier);
18   printf("%s starting...\n", __FUNCTION__);
19   for (uint32_t i = 0; i < 10; ++i)
20     g_val = i;
21 }
22 
23 int main(int argc, char const *argv[]) {
24   printf("Before running the thread\n");
25   pseudo_barrier_init(g_barrier, 2);
26   std::thread thread(thread_func);
27 
28   printf("After running the thread\n");
29   pseudo_barrier_wait(g_barrier);
30 
31   thread.join();
32 
33   return 0;
34 }
35