Skip to content

Instantly share code, notes, and snippets.

@dadhi
Created August 13, 2025 14:17
Show Gist options
  • Save dadhi/5d39ad164b2a68344a19d151e9b0e1ae to your computer and use it in GitHub Desktop.
Save dadhi/5d39ad164b2a68344a19d151e9b0e1ae to your computer and use it in GitHub Desktop.
ThreadSleepYieldMeaning
// source: https://github.com/dotnet/runtime/discussions/115627#discussioncomment-14092390
// Thread.Sleep(0); // 4750 cede control to any thread of equal priority
// spinWait.SpinOnce(); // 4100 periodically yields (default is 10 iterations)
// Thread.Sleep(1); // 3900 cede control to any thread of OS choice
// Thread.Yield(); // 3650 cede control to any thread on the same core
// await Task.Delay(0); // 3600 creates and waits on a system timer
// do nothing // 3600 burn down a CPU core
// Thread.SpinWait(1); // 3600 duration-limited Yield
// await Task.Yield(); // 3250 suspend task indefinitely (scheduler control)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment