-
Notifications
You must be signed in to change notification settings - Fork 0
Variadic templating refactor #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,10 @@ threadpool::threadpool(const int& n) { | |
| lock.unlock(); | ||
| break; | ||
| } | ||
| std::optional<task> opt_task = this->poll_task(); | ||
| if (opt_task.has_value()) { | ||
| auto& task = opt_task.value(); | ||
|
|
||
| if (!tasks.empty()) { | ||
| auto task = std::move(tasks.front()); | ||
| tasks.pop(); | ||
|
Comment on lines
+22
to
+24
|
||
| lock.unlock(); | ||
| task(); | ||
| } | ||
|
|
@@ -30,6 +31,9 @@ threadpool::threadpool(const int& n) { | |
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| threadpool::~threadpool() { | ||
| std::unique_lock<std::mutex> lock(queue_stop_mutex); | ||
| if (!(m_Stop)) { | ||
|
|
@@ -62,19 +66,7 @@ void threadpool::shutdown_now() { | |
| } | ||
|
|
||
| [[nodiscard]] | ||
| int threadpool::queue_size() { | ||
| size_t threadpool::queue_size() { | ||
| std::lock_guard<std::mutex> lock(queue_stop_mutex); | ||
| return tasks.size(); | ||
| } | ||
|
|
||
| // ============ THREADPOOL PRIVATE ============ | ||
|
|
||
| std::optional<task> threadpool::poll_task() { | ||
| // No lock guard as the thread would already have the guard | ||
| if (tasks.empty()) { | ||
| return std::nullopt; | ||
| } | ||
| task front = tasks.front(); | ||
| tasks.pop(); | ||
| return front; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Fibonacci numbers were changed from computing fib(20), fib(30), fib(40) to computing fib(10), fib(20), fib(30). While this change makes the demo run faster, it significantly reduces the computational workload and may not effectively demonstrate the threadpool's ability to handle parallel CPU-intensive tasks. The original values provided a better stress test for the threadpool.