62 cout <<
"test-con-queue -- demonstrates QueueTheadsPool concurrent processing\n"
64 <<
"Creates a pool of worker threads backed by a shared queue. Each thread\n"
65 <<
"runs one of two event types (Event1 / Event2), both of which sleep for\n"
66 <<
WORK_DELAY_MS <<
" ms to simulate work. The test enqueues items, lets workers\n"
67 <<
"run for a while, then suspends, sleeps, resumes, and finally shuts down.\n"
70 <<
" " <<
argv[0] <<
" <num_threads> <num_items> <secs>\n"
73 <<
" num_threads Number of worker threads to create (positive integer)\n"
74 <<
" num_items Number of integer items to enqueue\n"
75 <<
" secs Seconds to let workers run in each active phase\n"
78 <<
" " <<
argv[0] <<
" 4 100 3\n"
79 <<
" Creates 4 threads, enqueues 100 items, runs for 3 s, suspends,\n"
80 <<
" sleeps 5 s, resumes for another 3 s, then shuts down.\n";
86 cerr <<
"Usage: " <<
argv[0] <<
" <num_threads> <num_items> <secs>" <<
endl;
92 if (
argv[1][0] ==
'-')
104 if (
argv[2][0] ==
'-')
116 if (
argv[3][0] ==
'-')
130 for (
size_t i = 0; i < num_threads; ++i)
140 cout <<
"Inserting " << num_items <<
" to the queue" <<
endl;
141 for (
size_t i = 0; i < num_items; ++i)
143 cout <<
"Inserting " << i <<
endl;
146 cout <<
"Done" <<
endl
148 <<
"Resuming ... " <<
endl;
152 <<
"Sleeping for " <<
secs <<
" seconds" <<
endl;
153 this_thread::sleep_for(chrono::seconds(
secs));
157 <<
"List of event counters" <<
endl;
160 cout <<
" Event count = " << e->get_count() <<
endl;
163 cout <<
"done" <<
endl
165 <<
"Suspending (cooperative: in-flight tasks continue in run())" <<
endl;
167 cout <<
"Done" <<
endl
169 <<
"Sleeping for 5 secs" <<
endl;
170 this_thread::sleep_for(chrono::seconds(5));
171 cout <<
"done" <<
endl
173 <<
"Resuming while other " <<
secs <<
" seconds" <<
endl
176 this_thread::sleep_for(chrono::seconds(
secs));
180 <<
"List of event counters" <<
endl;
183 cout <<
" Event count = " << e->get_count() <<
endl;
186 cout <<
"done" <<
endl
188 <<
"Shutdown" <<
endl;
190 cout <<
"Done" <<
endl;
Dynamic singly linked list with functional programming support.
T & append(const T &item)
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
void increment_count() noexcept
Pool of consumer threads form a queue.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
Queue-based consumer thread pool.
void run() override
this is a item extracted from the queue
void run() override
this is a item extracted from the queue
static constexpr size_t WORK_DELAY_MS