Skip to content

Instantly share code, notes, and snippets.

@omariom
Created January 20, 2023 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omariom/cd4e410c452f1b7885b83f86bb6ef4c1 to your computer and use it in GitHub Desktop.
Save omariom/cd4e410c452f1b7885b83f86bb6ef4c1 to your computer and use it in GitHub Desktop.
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