It's simply:
boost::thread(&process_request, some_ptr).detach();
You can replace boost
by std
and your program is portable in c++11.
Note that process_request
can actually take the parameter strong-typed now. If you want to pass a reference, use boost::ref
(or std::ref
, indeed):
void process_request(MyData& data)
{
}
MyData data;
boost::thread th(&process_request, boost::ref(data));
th.join();
It's a bit of a pattern in C++11, though, to move the data into the thread function, so as to avoid races on the parameters being passed:
void process_request(MyData&& data)
{
}
MyData data;
boost::thread th(&process_request, std::move(data));
th.join();