0
: 여기 ... https://github.com/progschj/ThreadPool전송 함수 포인터가 나는이 동료에서 ThreadPool이 구현을 사용하려고 해요
나는 문제가 enqueue
방법 '기능'을 추가하는 데있어 인 아래 enqueue
방법에 대한 구현 :
#include "ThreadPool.h"
#include <stdio.h>
#include <iostream>
int main() {
// create a thread pool of 4 worker threads
ThreadPool pool(4);
// queue a bunch of "work items"
for(int i = 0; i < 8; ++i) {
pool.enqueue([i] {
std::cout << "hello " << i << std::endl;
std::cout << "world " << i << std::endl;
});
}
}
그것은이 샘플 코드의 일부입니다 : 여기
// add new work item to the pool
template<class T, class F>
Result<T> ThreadPool::enqueue(F f)
{
Result<T> res;
{
std::unique_lock<std::mutex> lock(queue_mutex);
tasks.push_back(std::function<void()>(
[f,res]()
{
CallAndSet<T,F>()(res, f);
}));
}
condition.notify_one();
return res;
}
내가 사용하고 무엇 라이브러리를 사용하는 방법을 보여 주려 ... 컴파일에서
출력은 : 그것은 stuff..I가 아무 생각하는 주형에 관해서
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build
g++ -o build/main.o -c -std=c++11 -pthread -Wall -g main.cpp
main.cpp: In function 'int main()':
main.cpp:15:7: error: no matching function for call to 'ThreadPool::enqueue(main()::<lambda()>)'
main.cpp:15:7: note: candidate is:
In file included from main.cpp:1:0:
ThreadPool.h:117:15: note: template<class T, class F> Result<T> ThreadPool::enqueue(F)
ThreadPool.h:117:15: note: template argument deduction/substitution failed:
main.cpp:15:7: note: couldn't deduce template parameter 'T'
scons: *** [build/main.o] Error 1
scons: building terminated because of errors.
내가 꽤 우둔 해요 이유는 위하지 않습니다 ... 누구든지 아이디어가 있습니까?
환호
자렛
끝내주었습니다. 감사합니다. @pmr! 'TheType'을'void'로 설정하면 매력처럼 작동합니다. – Jarrett
@Jarrett 문서를보고 무언가가 실제로 원하는 것인지를 확인하십시오. 또한 버그를 신고하십시오. 이것은 확실히 개선 될 수 있습니다. – pmr
예, 분명히'Result'는'std :: future'와 같아서'T'와 함께 계산의 'result'클래스를 지정해야합니다 ... I _think_'void' is is 유효한 (즉, 보내지는 함수의 실행에 의해 반환되는 값은 없습니다). – Jarrett