manatttta
manatttta

Reputation: 3124

ThreadPool class: can't pass the args straight

I have a Thread pool of the type that can be found here.

I try doing the following:

/* Allocate a ThreadPool */
shared_ptr<SpinTools::ThreadPool> pool(new SpinTools::ThreadPool(4));

/* Start processing each image in Core container */
for (int img_idx = 0; img_idx < num_images; img_idx++) {

    pool->enqueue(_worker_task, img_idx, _args, _stats);

}

My worker task has the following prototype:

void _worker_task(int img_idx, ProcessorArgs &args, Stats &stats)

however this won't compile and MSVC displays the error

Error   14  error LNK2019: unresolved external symbol "public: class std::future<void> __cdecl ThreadPool::enqueue<void (__cdecl&)(int,struct ProcessorArgs,struct SpinCore::Features::Stats &),int &,struct Sift::ProcessorArgs &,struct SpinCore::Features::Stats &>(void (__cdecl&)(int,struct ProcessorArgs,struct SpinCore::Features::Stats &),int &,struct ProcessorArgs &,struct SpinCore::Features::Stats &)" (??$enqueue@A6AXHUProcessorArgs@Sift@@AEAUStats@Features@SpinCore@@@ZAEAHAEAU12@AEAU345@@ThreadPool@SpinTools@@QEAA?AV?$future@X@std@@A6AXHUProcessorArgs@Sift@@AEAUStats@Features@SpinCore@@@ZAEAHAEAU45@1@Z) referenced in function "public: virtual void __cdecl Sift::process(void)" (?process@Sift@@UEAAXXZ) 

Edit: adding the header for ThreadPool::enqueue for completness:

template<class F, class... Args>
auto enqueue(F&& f, Args&&... args) 
    -> std::future<typename std::result_of<F(Args...)>::type>;

Upvotes: 0

Views: 140

Answers (1)

user3458
user3458

Reputation:

You need to place the implementation of ThreadPool::enqueue in the header. MSVC can't generate the implementation if it's in .cpp file only (or at least earlier versions could not)

Upvotes: 1

Related Questions