Reputation: 14251
I am trying to create a daemon thread in c++ for windows using the native apis, but I cannot seem to find any reference to daemon threads. Does anyone have a link to the documentation relating to this, or is there a different term for this on windows? How do I create a daemon thread on windows in c++?
Upvotes: 3
Views: 4557
Reputation: 36318
In Windows, your main thread should either call ExitProcess
or return from the main() function when the process is ready to exit. If there are other threads running that should not be terminated, it is your responsibility to keep track of this and not exit from the main function until those threads are complete.
In practice, this means that all threads are "daemon threads".
(In principle, no threads are daemon threads; if you explicitly kill the main thread, the process will not exit until all threads have exited. Unfortunately, this includes threads that Windows created automatically for you, some of which might not ever exit, so this is not a good idea.)
Upvotes: 1