lundi 22 décembre 2014

Can't pass parameters to std::thread?

I'm trying to use std::thread. My thread is supposed to call a method and pass a struct as a parameter, as so many examples show. Except my very simple code won't compile. For the record, I'm aware of this question but nothing there seems to help me.


Where I call the thread:



void Exporter::save() const {
thread(write_to_disk, this->parameter).detach();
}


The signature of write_to_disk:



void write_to_disk(const Parameter& parameter)


write_to_disk is defined in a nameless namespace in the .cpp file.


I get the following error:



src/Exporter.cpp:65:5: error: no matching constructor for initialization of 'std::__1::thread'
thread(write_to_disk, this->parameter).detach();
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/http://ift.tt/1CvC1us: note: candidate constructor template not viable: requires single argument '__f', but 2 arguments were provided
thread::thread(_Fp __f)
^
/Applications/http://ift.tt/1CvC1ux: note: candidate constructor not viable: requires 1 argument, but 2 were provided
thread(const thread&);
^
/Applications/http://ift.tt/1CvC1uB: note: candidate constructor not viable: requires 0 arguments, but 2 were provided
thread() _NOEXCEPT : __t_(0) {}
^

Aucun commentaire:

Enregistrer un commentaire