I've come to a problem using the new c++11 std::thread
interface.
I can't figure out how to pass a reference to a std::ostream
to the function that the thread will execute.
Here's an example with passing an integer(compile and work as expected under gcc 4.6) :
void foo(int &i) {
/** do something with i **/
std::cout << i << std::endl;
}
int k = 10;
std::thread t(foo, k);
But when I try passing an ostream it does not compile :
void foo(std::ostream &os) {
/** do something with os **/
os << "This should be printed to os" << std::endl;
}
std::thread t(foo, std::cout);
Is there a way to do just that, or is it not possible at all ??
NB: from the compile error it seems to come from a deleted constructor...