c++ - deque iterator not dereferencable error in thread pool -
i've written thread pool using sdl2's threading library, uses following thread function:
int threadfunc(void * pdata) { threaddata* data = (threaddata*)pdata; sdltaskmanager* pool = data->pool; task* task = nullptr; while (true) { sdl_lockmutex(pool->getmutex()); while (!pool->isrunning() && !pool->hastasks()) { sdl_condwait(pool->getcondition(), pool->getmutex()); } if (pool->shuttingdown()) { return 0; } task = pool->getnexttask(); //sdl_condwait relocks mutex, *should* thread safe. if (task != nullptr) { pool->notifythreadworking(true); data->taskcount++; } else { pool->stop(); sdl_unlockmutex(pool->getmutex()); continue; } sdl_unlockmutex(pool->getmutex()); task->execute(); sdl_lockmutex(pool->getmutex()); pool->notifythreadworking(false); pool->addcompletetask(task); sdl_unlockmutex(pool->getmutex()); } return 0; } i debug assertation error "deque iterator not dereferencable", when pool->getnexttask() called. i've checked contents of deque pool maintains via call stack , found it's not empty when function called.
the function code follows:
task * sdltaskmanager::getnexttask() { task* t = nullptr; if (!mcurrenttasks.empty()) { t = mcurrenttasks.front(); //this part causing error mcurrenttasks.pop_front(); //this std::deque<task*> } return t; } the deque has valid data in it, i'm @ loss causing problem.
Comments
Post a Comment