|
| 1 | +/* |
| 2 | +Copyright (c) 2012 Jakob Progsch, Václav Zeman |
| 3 | +
|
| 4 | +This software is provided 'as-is', without any express or implied |
| 5 | +warranty. In no event will the authors be held liable for any damages |
| 6 | +arising from the use of this software. |
| 7 | +
|
| 8 | +Permission is granted to anyone to use this software for any purpose, |
| 9 | +including commercial applications, and to alter it and redistribute it |
| 10 | +freely, subject to the following restrictions: |
| 11 | +
|
| 12 | + 1. The origin of this software must not be misrepresented; you must not |
| 13 | + claim that you wrote the original software. If you use this software |
| 14 | + in a product, an acknowledgment in the product documentation would be |
| 15 | + appreciated but is not required. |
| 16 | +
|
| 17 | + 2. Altered source versions must be plainly marked as such, and must not be |
| 18 | + misrepresented as being the original software. |
| 19 | +
|
| 20 | + 3. This notice may not be removed or altered from any source |
| 21 | + distribution. |
| 22 | +*/ |
| 23 | + |
1 | 24 | #ifndef THREAD_POOL_HPP |
2 | 25 | #define THREAD_POOL_HPP |
3 | 26 |
|
| 27 | +// containers |
4 | 28 | #include <vector> |
5 | 29 | #include <queue> |
6 | | -#include <memory> |
| 30 | +// threading |
7 | 31 | #include <thread> |
8 | 32 | #include <mutex> |
9 | 33 | #include <condition_variable> |
10 | 34 | #include <atomic> |
11 | 35 | #include <future> |
| 36 | +// utility wrappers |
| 37 | +#include <memory> |
12 | 38 | #include <functional> |
| 39 | +// exceptions |
13 | 40 | #include <stdexcept> |
14 | 41 |
|
| 42 | +// std::thread pool for resources recycling |
15 | 43 | class ThreadPool { |
16 | 44 | public: |
17 | 45 | // the constructor just launches some amount of workers |
@@ -44,6 +72,7 @@ class ThreadPool { |
44 | 72 | } |
45 | 73 | ); |
46 | 74 | } |
| 75 | + // deleted copy&move ctors&assignments |
47 | 76 | ThreadPool(const ThreadPool&) = delete; |
48 | 77 | ThreadPool& operator=(const ThreadPool&) = delete; |
49 | 78 | ThreadPool(ThreadPool&&) = delete; |
@@ -82,7 +111,8 @@ class ThreadPool { |
82 | 111 | // synchronization |
83 | 112 | std::mutex queue_mutex; |
84 | 113 | std::condition_variable condition; |
| 114 | + // workers finalization flag |
85 | 115 | std::atomic_bool stop; |
86 | 116 | }; |
87 | 117 |
|
88 | | -#endif |
| 118 | +#endif // THREAD_POOL_HPP |
0 commit comments