85# include <condition_variable>
118template <
class WorkerFct>
119class [[deprecated(
"WorkersSet goes in 8.0.0: use ThreadPool (thread_pool.H)")]]
124 WorkerFct worker_fct =
nullptr;
125 size_t num_threads = 0;
126 size_t queue_capacity = 0;
127 mutable std::mutex
m;
130 std::atomic<size_t> num_workers = 0;
134 bool shut_down =
false;
135 bool job_done =
false;
143 std::unique_lock<std::mutex> lock(
m);
146 cond.wait(lock, [
this] {
return num_workers > 0 or shut_down; });
150 while (num_workers > 0)
152 cond.wait(lock, [
this]
154 return (not q.
is_empty()) or shut_down;
162 void * pars_ptr = q.
get();
172 done = (*worker_fct)(pars_ptr);
174 catch (std::exception & e)
176 std::cout <<
"Warning: workers exception "
177 << e.what() << std::endl;
181 std::cout <<
"Warning: workers exception" << std::endl;
187 job_done_cond.notify_all();
195 job_done_cond.notify_all();
209 const size_t qsize,
const size_t n = 16)
210 : worker_fct(worker_fct), num_threads(n), queue_capacity(qsize), q(qsize)
212 for (
size_t i = 0; i < n; ++i)
224 std::unique_lock<std::mutex> lock(
m);
227 job_done_cond.notify_all();
247 std::unique_lock<std::mutex> lock(
m);
269 std::unique_lock<std::mutex> lock(
m);
271 <<
"WorkersSet::schedule_call(): the queue holds " << queue_capacity
284 std::unique_lock<std::mutex> lock(
m);
301 std::unique_lock<std::mutex> lock(
m);
302 job_done_cond.wait(lock, [
this]
303 {
return num_workers == 0 or job_done or shut_down; });
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
Very simple queue implemented with a contiguous array.
T & put(const T &item) noexcept
Put an item into the queue by copy.
constexpr bool is_empty() const noexcept
Return true if the queue is empty.
T get() noexcept
Remove the oldest item of the queue.
constexpr size_t size() const noexcept
Return the number of items.
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, T > void mutable_for_each(Operation &operation)
Apply a mutable operation to each element of the container.
Main namespace for Aleph-w library functions.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Circular queue implementations backed by arrays.