In the "C++ concurrency in action" book there is an example:
class background_task
{
public:
void operator() () const {
do_something();
do_something_else();
}
};
background_task f;
std::thread my_thread(f);
Followed by the text: "In this case, the supplied function object is copied into the storage belonging to the newly created thread of execution and invoked from there. It's therefore essential that the copy behave equivalently to the original, or the result may not be what's expected."
Could someone please explain to me in more details what these two sentences mean? What about other callable types that can be supplied to the thread object's constructor, are they not copied? How do I make sure that "the copy behave equivalently to the original" or why would it not behave equivalently? Thank you!