37{
38 std::cout << "=== Thread Integration Example ===" << std::endl;
39
40
41 std::cout << "\n1. Creating thread pool (4 workers):" << std::endl;
42 auto pool = std::make_shared<integration::basic_thread_pool>(4);
43 std::cout << " Worker count: " << pool->worker_count() << std::endl;
44 std::cout << " Running: " << (pool->is_running() ? "yes" : "no") << std::endl;
45
46
47 std::cout << "\n2. Submitting tasks:" << std::endl;
48 std::atomic<int> completed{0};
49
50 std::vector<std::future<void>> futures;
51 for (int i = 0; i < 5; ++i)
52 {
53 auto future = pool->submit(
54 [i, &completed]()
55 {
56 std::this_thread::sleep_for(std::chrono::milliseconds(50));
57 completed.fetch_add(1);
58 std::cout << " Task " << i << " completed on thread "
59 << std::this_thread::get_id() << std::endl;
60 });
61 futures.push_back(std::move(future));
62 }
63
64
65 for (auto& f : futures)
66 {
67 f.get();
68 }
69 std::cout << " All " << completed.load() << " tasks completed" << std::endl;
70
71
72 std::cout << "\n3. Thread integration manager:" << std::endl;
74 manager.set_thread_pool(pool);
75
76 auto global_pool = manager.get_thread_pool();
77 std::cout << " Global pool set: " << (global_pool != nullptr ? "yes" : "no") << std::endl;
78
79
80 auto task_future = manager.submit_task(
81 []() { std::cout << " Task submitted via global manager" << std::endl; });
82 task_future.get();
83
84
85 std::cout << "\n4. Pool metrics:" << std::endl;
86 std::cout << " Workers: " << pool->worker_count() << std::endl;
87 std::cout << " Pending: " << pool->pending_tasks() << std::endl;
88 std::cout << " Completed: " << pool->completed_tasks() << std::endl;
89
90
91 std::cout << "\n5. Stopping pool..." << std::endl;
92 pool->stop(true);
93 std::cout << " Running: " << (pool->is_running() ? "yes" : "no") << std::endl;
94
95 std::cout << "\nDone." << std::endl;
96 return 0;
97}
static thread_integration_manager & instance()
Get the singleton instance.