1 //===-- main.cpp ------------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
15 #define NUM_OF_THREADS 4
17 std::mutex hw_break_mutex;
20 hw_break_function (uint32_t thread_index) {
21 printf ("%s called by Thread #%u...\n", __FUNCTION__, thread_index);
26 thread_func (uint32_t thread_index) {
27 printf ("%s (thread index = %u) starting...\n", __FUNCTION__, thread_index);
29 hw_break_mutex.lock();
31 hw_break_function(thread_index); // Call hw_break_function
33 hw_break_mutex.unlock();
37 int main (int argc, char const *argv[])
39 std::thread threads[NUM_OF_THREADS];
41 printf ("Starting thread creation with hardware breakpoint set...\n");
43 for (auto &thread : threads)
44 thread = std::thread{thread_func, std::distance(threads, &thread)};
46 for (auto &thread : threads)