cuDDL
Loading...
Searching...
No Matches
Public Member Functions | List of all members
cuddl::detail::worker_pool Class Reference

Fixed threads that run indexed work with the caller, for work repeated per batch. More...

#include <worker_pool.hpp>

Public Member Functions

 worker_pool (size_t workers)
 
 worker_pool (worker_pool const &)=delete
 
worker_pool & operator= (worker_pool const &)=delete
 
 ~worker_pool ()
 
template<typename Work >
void for_each (size_t count, Work &&work)
 Runs work(index) for every index below count; one call at a time.
 

Detailed Description

Fixed threads that run indexed work with the caller, for work repeated per batch.

Spawning and joining threads for every batch cost the thread submitting batches more time than the reads it spread over them.

Definition at line 17 of file worker_pool.hpp.

Constructor & Destructor Documentation

◆ worker_pool() [1/2]

cuddl::detail::worker_pool::worker_pool ( size_t  workers)
inlineexplicit

Definition at line 19 of file worker_pool.hpp.

19 {
20 auto const helpers = workers > 0 ? workers - 1 : 0;
21 threads_.reserve(helpers);
22 for (size_t thread = 0; thread < helpers; ++thread) {
23 threads_.emplace_back([this] { serve(); });
24 }
25 }

◆ worker_pool() [2/2]

cuddl::detail::worker_pool::worker_pool ( worker_pool const &  )
delete

◆ ~worker_pool()

cuddl::detail::worker_pool::~worker_pool ( )
inline

Definition at line 28 of file worker_pool.hpp.

28 {
29 {
30 std::lock_guard lock(mutex_);
31 stop_ = true;
32 }
33 start_.notify_all();
34 for (auto& thread : threads_) thread.join();
35 }

Member Function Documentation

◆ for_each()

template<typename Work >
void cuddl::detail::worker_pool::for_each ( size_t  count,
Work &&  work 
)
inline

Runs work(index) for every index below count; one call at a time.

Definition at line 39 of file worker_pool.hpp.

39 {
40 if (count == 0) return;
41 auto run = [&](size_t index) {
42 work(index);
43 };
44 {
45 std::lock_guard lock(mutex_);
46 job_ = run;
47 count_ = count;
48 next_ = 0;
49 active_ = threads_.size();
50 ++generation_;
51 }
52 start_.notify_all();
53 drain();
54 std::unique_lock lock(mutex_);
55 done_.wait(lock, [&] { return active_ == 0; });
56 job_ = nullptr;
57 }
auto const count
Definition kernels.cuh:1031
__global__ uint16_t const uint32_t uint32_t uint32_t unsigned long long * work
Definition kernels.cuh:474

◆ operator=()

worker_pool & cuddl::detail::worker_pool::operator= ( worker_pool const &  )
delete

The documentation for this class was generated from the following file: