|
C++ Concurrency Sandbox
|
Advanced Thread Pool implementation with dynamic return types and CLI test harness. More...
#include <iostream>#include <vector>#include <thread>#include <functional>#include <mutex>#include <queue>#include <condition_variable>#include <atomic>#include <future>#include <memory>#include <utility>#include <algorithm>Go to the source code of this file.
Classes | |
| struct | TaskWrapper |
| A functor that wraps a packaged_task shared pointer. More... | |
| class | ThreadPool_Advanced |
| A pool of persistent worker threads for concurrent task execution. More... | |
Typedefs | |
| typedef std::function< void()> | Task |
| Type alias for a generic void-returning function. Used internally by the worker threads to process the task queue. | |
Functions | |
| int | multiply (int a, int b) |
| Simulates an intensive multiplication operation. | |
| std::pair< bool, int > | isPrime (int n) |
| Checks if a number is prime. | |
| int | main () |
| Main entry point to demonstrate the Request-Response pattern. | |
Variables | |
| std::mutex | log_mtx |
| Global mutex for synchronized console logging. Prevents race conditions and interleaved output when multiple threads log to stdout. | |
Advanced Thread Pool implementation with dynamic return types and CLI test harness.
Definition in file ThreadPool_Advanced.cpp.
Type alias for a generic void-returning function. Used internally by the worker threads to process the task queue.
Alias for a generic callable object.
Alias for a callable object with a void() signature.
Type alias for a basic void function with no arguments.
Definition at line 27 of file ThreadPool_Advanced.cpp.
| std::pair< bool, int > isPrime | ( | int | n | ) |
Checks if a number is prime.
| n | The integer to check. |
Definition at line 160 of file ThreadPool_Advanced.cpp.
Referenced by main().
| int main | ( | void | ) |
Main entry point to demonstrate the Request-Response pattern.
Definition at line 174 of file ThreadPool_Advanced.cpp.
References ThreadPool_Advanced::enqueue(), isPrime(), and multiply().
| int multiply | ( | int | a, |
| int | b | ||
| ) |
Simulates an intensive multiplication operation.
| a | First factor. |
| b | Second factor. |
Definition at line 150 of file ThreadPool_Advanced.cpp.
Referenced by main().
| std::mutex log_mtx |
Global mutex for synchronized console logging. Prevents race conditions and interleaved output when multiple threads log to stdout.
Definition at line 33 of file ThreadPool_Advanced.cpp.