Я работаю над созданием диспетчера заданий, который будет иметь пул потоков рабочих потоков, и каждый из этих рабочих потоков будет извлекать из очереди и выполнять заданные задания, если таковые имеются.
То, с чем я борюсь, на самом деле вызывает указатель функции, который я сохранил в параллельной очереди.
Я определил структуру CpuJob
следующим образом:
class ITask {}; // An interface that should be inherited
// from if you want your class to be "Jobified"
typedef void ( ITask::*task_func )( void*, int ); // A job function
// MUST take a void* and an int
struct CpuJob
{
task_func task_func_ptr;
void* args = nullptr;
int index = 0;
};
А вот моя AddJob
Функция:
void Jobs::JobManager::AddJob_Member( task_func aJob, void * aArgs, int aIndex )
{
CpuJob temp = {};
temp.task_func_ptr = aJob;
temp.args = aArgs;
temp.index = aIndex;
readyQueue.emplace_back( temp ); // This is a wrapper around std::queue to be concurrent and thread safe
jobAvailableCondition.notify_one();
}
И внутри моего рабочего потока,где я хочу вызвать указатель сохраненной функции, где я получаю свою ошибку:
// Other stuff popping jobs off the queue
if ( !readyQueue.empty() )
{
CpuJob CurJob;
readyQueue.pop_front( CurJob );
CurJob.task_func_ptr( CurJob.args, CurJob.index ); // This is giving me an error
// Notify other threads that a job has been taken and we should probably
// check to make sure that there isn;t more
jobAvailableCondition.notify_one();
}
Я получаю следующую ошибку:
Error (active) expression preceding parentheses of apparent call must have (pointer-to-) function type
Я думаю, что это как-то связано с тем, как я ссылаюсь на функцию, но я пробовал несколько способов сделать это безрезультатно.