5 static LoggerPtr logger(Logger::getLogger(
"TPZThreadPool"));
30 std::function<void(void) > thread_join_task;
48 typename std::thread::id thread_id = std::this_thread::get_id();
49 thread_join_task = [
this, thread_id] {
53 if (
mThreads[i].get_id() == thread_id) {
55 if (i != num_threads - 1) {
72 if (!thread_join_task) {
77 if (thread_join_task) {
78 runSystemTask(std::numeric_limits<int>::max(), thread_join_task);
90 int threads_to_create = numThreads - num_threads_before;
91 if (threads_to_create < 0) {
93 for (
unsigned int i = 0; i < -threads_to_create; ++i) {
97 for (
int i = 0; i < threads_to_create; ++i) {
112 std::shared_future<void> fut = task->get_future().share();
140 if (thread.joinable()) {
186 std::unique_lock<std::mutex> lock(task->
mStateMutex);
188 case TPZReschedulableTask::EProcessingState::CREATED:
192 tpztask->
mPriority = std::numeric_limits<int>::max();
194 task->
mState = TPZReschedulableTask::EProcessingState::SCHEDULED;
215 std::unique_lock<std::mutex> lock(task->
mStateMutex);
217 case TPZReschedulableTask::EProcessingState::CREATED:
223 task->
mState = TPZReschedulableTask::EProcessingState::SCHEDULED;
230 case TPZReschedulableTask::EProcessingState::SCHEDULED:
231 case TPZReschedulableTask::EProcessingState::STARTED:
232 case TPZReschedulableTask::EProcessingState::FINISHED:
240 return globalIntstance;
void addItem(const T &item)
Container::size_type size() const
clarg::argInt num_threads("-ntdec", "Number of threads to decompose in TPZParFrontStructMatrix.", 6)
unsigned int mThreadsToDelete
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
TPZTask(const int priority, TPZAutoPointer< std::packaged_task< void(void)>> &task, TPZTaskGroup *taskGroup=NULL)
int ActualThreadCount() const
std::condition_variable mTaskAvailableCond
Administers tasks that will be executed asynchronously.
std::mutex mThreadsMutex
one mutex to synchronize access to the data structures
std::shared_future< void > runSystemTask(const int priority, std::function< void(Args...) > func, Args... args)
Submits and processes a "maximum priority" system task.
void appendTaskToQueue(TPZAutoPointer< TPZTask > &task)
static TPZThreadPool & globalInstance()
TPZPriorityQueue< TPZAutoPointer< TPZTask >, std::vector< TPZAutoPointer< TPZTask > >, TPZTaskOrdering > mTasksQueue
void reschedule(const int priority, TPZAutoPointer< TPZReschedulableTask > &task)
std::shared_future< void > run(const int priority, TPZAutoPointer< std::packaged_task< void(void) > > &task, TPZTaskGroup *taskGroup=NULL)
submits a task to be executed by TPZThreadPool
void checkForMaxAndMinPriority(const int priority)
TPZAutoPointer< std::packaged_task< void(void)> > mTask
virtual void startInternal()
std::shared_future< void > mFuture
unsigned int mZombieThreads
void SetNumThreads(const unsigned numThreads)
sets the number of threads to be executed simultaneously
std::condition_variable mCondition
std::vector< std::thread > mThreads
vector of thread objects
std::shared_future< void > runNow(TPZAutoPointer< TPZReschedulableTask > &task)
This class implements a reference counter mechanism to administer a dynamically allocated object...