libgrape-lite
A C++ library for parallel graph processing
Public Member Functions | Private Attributes | List of all members
ThreadPool Class Reference

#include <thread_pool.h>

Public Member Functions

 ThreadPool (ThreadPool const &)=delete
 
ThreadPooloperator= (ThreadPool const &)=delete
 
void InitThreadPool (const grape::ParallelEngineSpec &)
 
template<class F , class... Args>
auto enqueue (F &&f, Args &&... args) -> std::future< grape::result_of_t< F, Args... >>
 
int GetThreadNum ()
 
void WaitEnd (std::vector< std::future< void >> &results)
 

Private Attributes

std::vector< std::thread > workers
 
std::queue< std::function< void()> > tasks
 
std::mutex queue_mutex
 
std::condition_variable condition
 
bool stop {false}
 
size_t thread_num_ {1}
 

Detailed Description

Credits to Jakob Progsch (@progschj) https://github.com/progschj/ThreadPool

Copyright (c) 2012 Jakob Progsch, Václav Zeman

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

Modified by Binrui Li at Alibaba Group, 2021.