38 std::cout <<
"=== Thread Integration Example ===" << std::endl;
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;
47 std::cout <<
"\n2. Submitting tasks:" << std::endl;
48 std::atomic<int> completed{0};
50 std::vector<std::future<void>> futures;
51 for (
int i = 0; i < 5; ++i)
53 auto future = pool->submit(
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;
61 futures.push_back(std::move(future));
65 for (
auto& f : futures)
69 std::cout <<
" All " << completed.load() <<
" tasks completed" << std::endl;
72 std::cout <<
"\n3. Thread integration manager:" << std::endl;
74 manager.set_thread_pool(pool);
76 auto global_pool = manager.get_thread_pool();
77 std::cout <<
" Global pool set: " << (global_pool !=
nullptr ?
"yes" :
"no") << std::endl;
80 auto task_future = manager.submit_task(
81 []() { std::cout <<
" Task submitted via global manager" << std::endl; });
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;
91 std::cout <<
"\n5. Stopping pool..." << std::endl;
93 std::cout <<
" Running: " << (pool->is_running() ?
"yes" :
"no") << std::endl;
95 std::cout <<
"\nDone." << std::endl;