UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
ThreadPool3.hxx
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*\
2 | |
3 | Copyright (C) 2025 |
4 | |
5 | , __ , __ |
6 | /|/ \ /|/ \ |
7 | | __/ _ ,_ | __/ _ ,_ |
8 | | \|/ / | | | | \|/ / | | | |
9 | |(__/|__/ |_/ \_/|/|(__/|__/ |_/ \_/|/ |
10 | /| /| |
11 | \| \| |
12 | |
13 | Enrico Bertolazzi |
14 | Dipartimento di Ingegneria Industriale |
15 | Università degli Studi di Trento |
16 | email: enrico.bertolazzi@unitn.it |
17 | |
18\*--------------------------------------------------------------------------*/
19
20//
21// file: ThreadPool3.hxx
22//
23
24#include "3rd/BS_thread_pool.hpp"
25
26namespace Utils {
27
32
33 /*\
34 | _____ _ _ ____ _
35 | |_ _| |__ _ __ ___ __ _ __| | _ \ ___ ___ | |
36 | | | | '_ \| '__/ _ \/ _` |/ _` | |_) / _ \ / _ \| |
37 | | | | | | | | | __/ (_| | (_| | __/ (_) | (_) | |
38 | |_| |_| |_|_| \___|\__,_|\__,_|_| \___/ \___/|_|
39 \*/
51 class ThreadPool3 : public ThreadPoolBase {
52
53 BS::light_thread_pool m_pool;
54
55 public:
56
63 unsigned nthread = std::max(
64 unsigned(1),
65 unsigned(std::thread::hardware_concurrency()-1)
66 )
67 ) : m_pool( nthread ) {}
68
74 virtual ~ThreadPool3() {}
75
81 void exec( FUN && fun ) override { m_pool.detach_task( std::move(fun) ); }
82
86 void wait() override { m_pool.wait(); }
87
93 unsigned thread_count() const override { return unsigned( m_pool.get_thread_count() ); }
94
100 static char const * Name() { return "ThreadPool3 [BS]"; }
101
102 char const * name() const override { return Name(); }
103
104 };
105
107
108}
109
110//
111// eof: ThreadPool3.hxx
112//
void wait() override
Waits for all tasks to be completed.
Definition ThreadPool3.hxx:86
ThreadPool3(unsigned nthread=std::max(unsigned(1), unsigned(std::thread::hardware_concurrency() -1)))
Constructs a new ThreadPool5 instance with a specified number of threads.
Definition ThreadPool3.hxx:62
void exec(FUN &&fun) override
Executes a task and assigns it to an available worker.
Definition ThreadPool3.hxx:81
static char const * Name()
Gets the name of the thread pool implementation.
Definition ThreadPool3.hxx:100
virtual ~ThreadPool3()
Destructor for the ThreadPool5 class.
Definition ThreadPool3.hxx:74
unsigned thread_count() const override
Gets the current number of threads in the pool.
Definition ThreadPool3.hxx:93
char const * name() const override
Definition ThreadPool3.hxx:102
ThreadPoolBase(ThreadPoolBase const &)=delete
std::function< void(void)> FUN
Definition ThreadPoolBase.hxx:55
Definition SystemUtils.cc:39