MCPcopy Create free account
hub / github.com/Compaile/ctrack / complex_operation

Function complex_operation

examples/complex_multithreaded_puzzle.cpp:44–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44void complex_operation(int id) {
45 CTRACK;
46 std::random_device rd;
47 std::mt19937 gen(rd());
48 std::uniform_int_distribution<> dis(1, 10);
49
50 for (int i = 0; i < 5; ++i) {
51 int random_num = dis(gen);
52 if (random_num % 2 == 0) {
53 nested_function_a(random_num);
54 } else {
55 nested_function_b(random_num);
56 }
57
58 if (random_num == 7) { // Rare slow path
59 recursive_work(20);
60 }
61
62 global_counter.fetch_add(1, std::memory_order_relaxed);
63 }
64
65 {
66 std::lock_guard<std::mutex> lock(cout_mutex);
67 std::cout << "Thread " << id << " completed." << std::endl;
68 }
69}
70
71int main() {
72 const int thread_count = 4;

Callers

nothing calls this directly

Calls 3

nested_function_aFunction · 0.85
nested_function_bFunction · 0.85
recursive_workFunction · 0.85

Tested by

no test coverage detected