#include "stdafx.h" #include <windows.h> int g_count; const int ThreadNum = 10; DWORD __stdcall Func(LPVOID pm) { Sleep(10); g_count++; //InterlockedIncrement((LPLONG)&g_count); return 0; } int main() { HANDLE handle[ThreadNum]; for (int k = 0; k < ThreadNum; ++k) { g_count = 0; for (int i = 0; i < ThreadNum; ++i) { handle[i] = CreateThread(NULL, 0, Func, (LPVOID)i, 0, NULL); } WaitForMultipleObjects(ThreadNum, handle, TRUE, INFINITE); printf_s("%d ", g_count); } system("pause"); return 0; }