MCPcopy Create free account
hub / github.com/Samsung/veles / ThreadPool

Method ThreadPool

libVeles/src/thread_pool.h:46–68  ·  view source on GitHub ↗

Constructor launches the requested number of workers.

Source from the content-addressed store, hash-verified

44 public:
45 /// Constructor launches the requested number of workers.
46 explicit ThreadPool(
47 size_t threads_number = std::thread::hardware_concurrency())
48 : stop_(false) {
49 assert(threads_number && "There must be 1 or more threads");
50 workers_.reserve(threads_number);
51 for(; threads_number; --threads_number) {
52 workers_.emplace_back([this] {
53 while (true) {
54 std::function<void()> task;
55 {
56 std::unique_lock<std::mutex> lock(mutex_);
57 condition_.wait(lock, [this]{ return stop_ || !tasks_.empty(); });
58 if (stop_ && tasks_.empty()) {
59 return;
60 }
61 task = std::move(tasks_.front());
62 tasks_.pop();
63 }
64 task();
65 }
66 });
67 }
68 }
69
70 ThreadPool(const ThreadPool&) = delete;
71 ThreadPool& operator=(const ThreadPool&) = delete;

Callers 5

thread_poolMethod · 0.80
test_pause_resumeMethod · 0.80
_doMethod · 0.80
test_0_threadsMethod · 0.80
test_double_shutdownMethod · 0.80

Calls

no outgoing calls

Tested by 4

test_pause_resumeMethod · 0.64
_doMethod · 0.64
test_0_threadsMethod · 0.64
test_double_shutdownMethod · 0.64