46 static std::atomic_uintmax_t _instance(0);
59, m_tot_task_count(std::make_shared<
atomic_int>(0))
61, m_task_lock(std::make_shared<
lock_t>())
62, m_main_tid(std::this_thread::get_id())
69 std::cerr << __FUNCTION__ <<
"@" << __LINE__ <<
" :: Warning! "
70 <<
"nullptr to thread pool!" << std::endl;
95 fprintf(stderr,
"%s @ %i :: Warning! nullptr to thread-pool (%p)\n",
96 __FUNCTION__, __LINE__,
static_cast<void*
>(
m_pool));
97 std::cerr << __FUNCTION__ <<
"@" << __LINE__ <<
" :: Warning! "
98 <<
"nullptr to thread pool!" << std::endl;
114 auto is_active_state = [&]() {
115 return (tpool->
state()->load(std::memory_order_relaxed) !=
116 thread_pool::state::STOPPED);
119 auto execute_this_threads_tasks = [&]() {
124 if((!_is_master || tpool->
size() < 2) && _within_task)
126 int bin =
static_cast<int>(taskq->GetThreadBin());
141 if(!_is_master || tpool->
size() < 2)
151 "%s @ %i :: Warning! nullptr to thread data (%p) or task-queue (%p)\n",
152 __FUNCTION__, __LINE__,
static_cast<void*
>(tpool),
153 static_cast<void*
>(taskq));
158 fprintf(stderr,
"%s @ %i :: Warning! thread-pool is not alive!\n",
159 __FUNCTION__, __LINE__);
161 else if(!is_active_state())
163 fprintf(stderr,
"%s @ %i :: Warning! thread-pool is not active!\n",
164 __FUNCTION__, __LINE__);
168 intmax_t wake_size = 2;
171 while(is_active_state())
173 execute_this_threads_tasks();
176 while(_is_master &&
pending() > 0 && is_active_state())
182 if(!_lock.owns_lock())
194 m_task_cond->wait_for(_lock, std::chrono::microseconds(100));
197 if(_lock.owns_lock())
206 if(_lock.owns_lock())
212 std::stringstream ss;
213 ss <<
"\nWarning! Join operation issue! " << ntask <<
" tasks still "
214 <<
"are running!" << std::endl;
215 std::cerr << ss.str();
std::atomic_uintmax_t & vtask_group_counter()
static TaskRunManager * GetMasterRunManager(bool useTBB=false)
ThreadPool * GetThreadPool() const
static ThreadData *& GetInstance()
VUserTaskQueue * current_queue
const pool_state_type & state() const
task_queue_t * get_queue() const
VTaskGroup(ThreadPool *tp=nullptr)
std::atomic_intmax_t atomic_int
atomic_int & task_count()
std::shared_ptr< condition_t > m_task_cond
virtual intmax_t pending()
virtual bool is_native_task_group() const
std::shared_ptr< lock_t > m_task_lock
VTask is the abstract class stored in thread_pool.