38 std::cout <<
"=== Example 1: Basic Capability Query ===" << std::endl;
40 auto mutex_queue = std::make_shared<job_queue>();
41 auto lockfree_queue = std::make_unique<detail::lockfree_job_queue>();
44 auto mutex_caps = mutex_queue->get_capabilities();
45 auto lockfree_caps = lockfree_queue->get_capabilities();
47 std::cout <<
"\njob_queue capabilities:" << std::endl;
48 std::cout <<
" exact_size: " << std::boolalpha << mutex_caps.exact_size << std::endl;
49 std::cout <<
" atomic_empty_check: " << mutex_caps.atomic_empty_check << std::endl;
50 std::cout <<
" lock_free: " << mutex_caps.lock_free << std::endl;
51 std::cout <<
" wait_free: " << mutex_caps.wait_free << std::endl;
52 std::cout <<
" supports_batch: " << mutex_caps.supports_batch << std::endl;
53 std::cout <<
" supports_blocking_wait: " << mutex_caps.supports_blocking_wait << std::endl;
54 std::cout <<
" supports_stop: " << mutex_caps.supports_stop << std::endl;
56 std::cout <<
"\ndetail::lockfree_job_queue capabilities:" << std::endl;
57 std::cout <<
" exact_size: " << lockfree_caps.exact_size << std::endl;
58 std::cout <<
" atomic_empty_check: " << lockfree_caps.atomic_empty_check << std::endl;
59 std::cout <<
" lock_free: " << lockfree_caps.lock_free << std::endl;
60 std::cout <<
" wait_free: " << lockfree_caps.wait_free << std::endl;
61 std::cout <<
" supports_batch: " << lockfree_caps.supports_batch << std::endl;
62 std::cout <<
" supports_blocking_wait: " << lockfree_caps.supports_blocking_wait << std::endl;
63 std::cout <<
" supports_stop: " << lockfree_caps.supports_stop << std::endl;
65 std::cout << std::endl;
75 std::cout <<
"=== Example 2: Convenience Methods ===" << std::endl;
77 auto queue = std::make_shared<job_queue>();
79 std::cout <<
"\nUsing convenience methods on job_queue:" << std::endl;
82 if (queue->has_exact_size()) {
83 std::cout <<
" [OK] Queue size is exact: " << queue->size() << std::endl;
86 if (queue->has_atomic_empty()) {
87 std::cout <<
" [OK] Empty check is atomic: " << std::boolalpha << queue->empty() << std::endl;
90 if (!queue->is_lock_free()) {
91 std::cout <<
" [OK] Queue uses mutex (good for accuracy)" << std::endl;
94 if (!queue->is_wait_free()) {
95 std::cout <<
" [OK] Queue is not wait-free" << std::endl;
98 if (queue->supports_batch()) {
99 std::cout <<
" [OK] Batch operations supported" << std::endl;
102 if (queue->supports_blocking_wait()) {
103 std::cout <<
" [OK] Blocking wait supported" << std::endl;
106 if (queue->supports_stop()) {
107 std::cout <<
" [OK] Stop signaling supported" << std::endl;
110 std::cout << std::endl;
239 std::cout <<
"=== Example 5: Capability Comparison Table ===" << std::endl;
241 auto mutex_q = std::make_shared<job_queue>();
242 auto lockfree_q = std::make_unique<detail::lockfree_job_queue>();
243 auto adaptive_q = std::make_unique<adaptive_job_queue>();
246 std::cout <<
"\n" << name <<
":" << std::endl;
247 std::cout <<
" exact_size = " << std::boolalpha << caps.exact_size << std::endl;
248 std::cout <<
" atomic_empty_check = " << caps.atomic_empty_check << std::endl;
249 std::cout <<
" lock_free = " << caps.lock_free << std::endl;
250 std::cout <<
" wait_free = " << caps.wait_free << std::endl;
251 std::cout <<
" supports_batch = " << caps.supports_batch << std::endl;
252 std::cout <<
" supports_blocking = " << caps.supports_blocking_wait << std::endl;
253 std::cout <<
" supports_stop = " << caps.supports_stop << std::endl;
256 print_caps(
"job_queue (mutex-based)", mutex_q->get_capabilities());
257 print_caps(
"detail::lockfree_job_queue", lockfree_q->get_capabilities());
258 print_caps(
"adaptive_job_queue (default mode)", adaptive_q->get_capabilities());
261 std::cout <<
"\n--- Summary Table ---" << std::endl;
262 std::cout <<
"Queue Type | exact | atomic | lock-free | batch | blocking" << std::endl;
263 std::cout <<
"----------------------|-------|--------|-----------|-------|----------" << std::endl;
265 auto caps = mutex_q->get_capabilities();
266 std::cout <<
"job_queue | "
267 << (caps.exact_size ?
"Y" :
"N") <<
" | "
268 << (caps.atomic_empty_check ?
"Y" :
"N") <<
" | "
269 << (caps.lock_free ?
"Y" :
"N") <<
" | "
270 << (caps.supports_batch ?
"Y" :
"N") <<
" | "
271 << (caps.supports_blocking_wait ?
"Y" :
"N") << std::endl;
273 caps = lockfree_q->get_capabilities();
274 std::cout <<
"detail::lockfree_job_queue | "
275 << (caps.exact_size ?
"Y" :
"N") <<
" | "
276 << (caps.atomic_empty_check ?
"Y" :
"N") <<
" | "
277 << (caps.lock_free ?
"Y" :
"N") <<
" | "
278 << (caps.supports_batch ?
"Y" :
"N") <<
" | "
279 << (caps.supports_blocking_wait ?
"Y" :
"N") << std::endl;
281 caps = adaptive_q->get_capabilities();
282 std::cout <<
"adaptive_job_queue | "
283 << (caps.exact_size ?
"Y" :
"N") <<
" | "
284 << (caps.atomic_empty_check ?
"Y" :
"N") <<
" | "
285 << (caps.lock_free ?
"Y" :
"N") <<
" | "
286 << (caps.supports_batch ?
"Y" :
"N") <<
" | "
287 << (caps.supports_blocking_wait ?
"Y" :
"N") << std::endl;
289 std::cout << std::endl;