Created
January 20, 2023 17:52
-
-
Save omariom/cd4e410c452f1b7885b83f86bb6ef4c1 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
const ulong UlongOne = 0x00000001_00000001; | |
const ulong UlongTwo = 0x00000002_00000002; | |
ulong ulongValue; | |
AutoResetEvent threadIsReady = new AutoResetEvent(false); | |
void Main() | |
{ | |
if (IntPtr.Size != 4) | |
{ | |
Console.WriteLine("The programm must be run in x86 mode."); | |
return; | |
} | |
for (int i = 0; i < 50; i++) | |
{ | |
var thread = new Thread(Thread); | |
thread.Start(); | |
threadIsReady.WaitOne(); | |
thread.Abort(); | |
thread.Join(); | |
if ((ulongValue >> 32) != (ulongValue & 0x00000000ffffffff)) | |
{ | |
Console.WriteLine("Torn write: {0} - {1:x}", i, ulongValue); | |
} | |
ulongValue = 0; | |
} | |
Console.WriteLine("Done"); | |
} | |
private void Thread(object parameter) | |
{ | |
threadIsReady.Set(); | |
while(true) | |
{ | |
// Try uncomment try/finally | |
//try {} finally { | |
ulongValue = UlongOne; | |
ulongValue = UlongTwo; | |
//} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment