7 std::default_random_engine g_random_engine
{std::random_device
{}()};
8 std::uniform_int_distribution
<> g_distribution
{0, 3000};
11 uint32_t lldb_val
= 0;
14 access_pool (bool flag
= false)
16 static std::mutex g_access_mutex
;
18 g_access_mutex
.lock();
20 uint32_t old_val
= g_val
;
25 g_access_mutex
.unlock();
30 thread_func (uint32_t thread_index
)
32 // Break here to test that the stop-hook mechanism works for multiple threads.
33 printf ("%s (thread index = %u) startng...\n", __FUNCTION__
, thread_index
);
39 // random micro second sleep from zero to .3 seconds
40 int usec
= g_distribution(g_random_engine
);
41 printf ("%s (thread = %u) doing a usleep (%d)...\n", __FUNCTION__
, thread_index
, usec
);
42 std::this_thread::sleep_for(std::chrono::microseconds
{usec
}); // Set break point at this line
47 val
= access_pool (true);
49 printf ("%s (thread = %u) after usleep access_pool returns %d (count=%d)...\n", __FUNCTION__
, thread_index
, val
, count
);
51 printf ("%s (thread index = %u) exiting...\n", __FUNCTION__
, thread_index
);
55 int main (int argc
, char const *argv
[])
57 std::thread threads
[3];
58 // Break here to set up the stop hook
59 printf("Stop hooks engaged.\n");
61 for (auto &thread
: threads
)
62 thread
= std::thread
{thread_func
, std::distance(threads
, &thread
)};
64 // Join all of our threads
65 for (auto &thread
: threads
)
68 // print lldb_val so we can check it here.
69 printf ("lldb_val was set to: %d.\n", lldb_val
);