-
-
Save slang25/39acdb0f404bad691e72f450d9266885 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
class Program | |
{ | |
static ManualResetEvent _produce = new ManualResetEvent(false); | |
static ManualResetEvent _consume = new ManualResetEvent(false); | |
private static void Run() | |
{ | |
while (true) | |
{ | |
_produce.WaitOne(); | |
_produce.Reset(); | |
ComputeHash(); | |
Console.WriteLine("Done"); | |
_consume.Set(); | |
} | |
} | |
[MethodImpl(MethodImplOptions.NoInlining)] | |
static void ComputeHash() | |
{ | |
var b = new byte[1024 * 1024 * 128]; | |
MD5.Create().ComputeHash(b); | |
} | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Press enter to start"); | |
Console.ReadLine(); | |
new Thread(Run) | |
{ | |
IsBackground = true, | |
}.Start(); | |
while (true) | |
{ | |
_produce.Set(); | |
_consume.WaitOne(); | |
_consume.Reset(); | |
GC.Collect(2); | |
GC.WaitForPendingFinalizers(); | |
Console.WriteLine(GC.GetTotalMemory(true)); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment