Referring to the relevant information, calling the exit function directly returns the process to the operating system, whether it is invoked in the main thread or the child thread, will directly control the control to the operating system.
Code 1: call exit in main thread to exit.
#include
#include
using namespace std;
void thread_fun()
{
cout<
The output is as follows:
Code 2: call exit function in sub thread
#include
#include
using namespace std;
void thread_fun()
{
cout<
The output is as follows:
It can be seen that after calling the exit function in the sub thread, the whole program is all out, including the child thread.