threadpool - C++ Simple Thread Pool -
i trying implement simple thread pool in c++ follows:
class worker { public: worker(); thread mthread; private: void run(); }; worker::worker() { (this->mthread = thread(&worker::run, this)).detach(); } class threadpool { public: threadpool(int size); void addtask(); private: vector<worker> workers; }; but when add constructor of threadpool:
threadpool::threadpool(int size) { this->workers = vector<worker>(size, worker()); } i "attempting reference deleted function" error far know means somewhere in code trying copy thread. there way solve problem?
smallest possible change to:
threadpool::threadpool(int size) { this->workers = vector<worker>(size); } that said, initialiser lists sweet.
threadpool::threadpool(int size) : workers{size} { } (you should change int size size_t or - if you're feeling saintly - vector<worker>::size_type).
it provision of prototypical worker() object requested copying, implicit constructor deleted because you'd provided explicit default constructor.
Comments
Post a Comment