multithreading - Does C++ 11 thread automatically destroy after detach -


normally, assume c++ 11 thread automatically destroy after detach. thing is, can't find prove assumption.

according this article

once detached, thread should live way forever.

forever? if function of thread finish, resource remain forever?

according this article

after call function, thread object becomes non-joinable , can destroyed safely.

it can destroyed safely, automatically?

if it's not destroyed automatically, how destroy (not forcefully, after function of thread end)

thanks reading.

you should consult better reference. std::thread::detach:

separates thread of execution thread object, allowing execution continue independently. allocated resources freed once thread exits.

after calling detach *this no longer owns thread.

so answer questions (if aren't already):

forever?

no. if thread finishes (for example: if counts 10), done , not running anymore.

does resource remain forever?

no, when thread finishes, every resource thread freed (like variables , such).

it can destroyed safely, automatically?

what mean? when thread done, destroyed (automatically), regardless of whether call detach or not. difference here, referring thread object, actual std::thread instance.

normally, std::thread's destructor waits thread finish, if call detach, associated thread detached, , std::thread instance not refer thread.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -