I have the following simple function, just for demonstration:
void thread_func(int i) {
return i;
}
And I have another function that calls it in a new thread and does not wait for it to return:
void my_nice_function() {
std::thread t(thread_func, 15);
}
Since t
is a local variable in my_nice_function()
, I am concerned that when my_nice_function()
exits, t
will be destroyed while running.
Is there a reason to be concerned?
How can I let the thread t
run in background even after returning from my_nice_function()
?