Unless one want a separate function in global namespacs, we can use lambda functions for creating threads.
One of the major advantage of creating thread using lambda is that we don't need to pass local parameters as an argument list. We can use capture list for the same and the closure property of lambda will take care of the lifecycle.
Here is a sample code
int main() {
int localVariable = 100;
thread th { [=](){
cout<<"The Value of local variable => "<<localVariable<<endl;
}};
th.join();
return 0;
}
By far, I've found C++ lambdas to be the best way of creating threads especially for simpler thread functions