Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DWORD WINAPI increment(CONST LPVOID lpParam)
- {
- CONST HANDLE hMutex = (CONST HANDLE)lpParam;
- while (testMutex < testMax)
- {
- WaitForSingleObject(hMutex, INFINITE);
- testMutex++;
- if(testMutex<testMax)
- std::cout << testMutex << std::endl;
- ReleaseMutex(hMutex);
- }
- ExitThread(0);
- }
- void createMutexAndThread()
- {
- HANDLE hMutex = CreateMutex(NULL, FALSE, NULL);
- HANDLE hThreads[500];
- for (int i = 0; i < 500; i++)
- {
- hThreads[i] = CreateThread(NULL, 0, &increment, hMutex, 0, NULL);
- }
- WaitForSingleObject(hThreads[0], INFINITE);
- //WaitForMultipleObjects(64, hThreads, TRUE, INFINITE);
- std::cout << "1n";
- for (int i = 0; i < 500; i++) {
- CloseHandle(hThreads[i]);
- }
- }
Add Comment
Please, Sign In to add comment