多线程运行不完整可能原因

1.创建线程时后面都加上sleep 等待一段时间

  hThread[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)mulit_thread_function, &g_arg[0], 0, NULL);
  Sleep(1000);
  hThread[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)mulit_thread_function, &g_arg[1], 0, NULL);
  Sleep(1000);
  hThread[2] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)mulit_thread_function, &g_arg[2], 0, NULL);
  Sleep(1000);
  hThread[3] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)mulit_thread_function, &g_arg[3], 0, NULL);
  Sleep(1000);

 WaitForMultipleObjects(MULTI_THREAD, hThread, TRUE, INFINITE);

 

2.线程函数内尽量不用全局变量,外部传入后可在函数内部定义一个相应的局部变量赋值后使用

你可能感兴趣的:(VS2013编程)