-
-
Save fredemmott/0a593248d48aaae8fb2c933e61c11d8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <chrono> | |
#include <thread> | |
#include <Windows.h> | |
int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int) { | |
{ | |
std::jthread a([]() { | |
std::this_thread::sleep_for(std::chrono::seconds(1)); | |
if (HeapLock(GetProcessHeap())) { | |
OutputDebugStringA("Locked heap in A\n"); | |
} | |
std::this_thread::sleep_for(std::chrono::seconds(10)); | |
OutputDebugStringA("About to unlock heap in A\n"); | |
if (HeapUnlock(GetProcessHeap())) { | |
OutputDebugStringA("Unlocked heap in A\n"); | |
} else { | |
OutputDebugStringA("Failed to unlock heap in A\n"); | |
} | |
}); | |
std::jthread b([]() { | |
std::this_thread::sleep_for(std::chrono::seconds(2)); | |
if (HeapUnlock(GetProcessHeap())) { | |
OutputDebugStringA("Unlocked in B\n"); | |
} else { | |
OutputDebugStringA("Failed to unlock in B\n"); | |
} | |
if (HeapLock(GetProcessHeap())) { | |
OutputDebugStringA("Locked in B\n"); | |
HeapUnlock(GetProcessHeap()); | |
} | |
}); | |
std::jthread c([]() { | |
std::this_thread::sleep_for(std::chrono::seconds(3)); | |
HeapLock(GetProcessHeap()); | |
OutputDebugStringA("Locked in C\n"); | |
HeapUnlock(GetProcessHeap()); | |
}); | |
} | |
OutputDebugStringA("Finished all threads\n"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Locked heap in A | |
Unlocked in B | |
Locked in B | |
Locked in C | |
About to unlock heap in A | |
Unlocked heap in A | |
Finished all threads |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment