Created
September 6, 2012 21:39
-
-
Save peteraritchie/3660551 to your computer and use it in GitHub Desktop.
show TPL using more threads than CPUs
This file contains hidden or 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
int threadCount = Environment.ProcessorCount + 5; | |
Parallel.ForEach(Enumerable.Range(0, threadCount), | |
new ParallelOptions { MaxDegreeOfParallelism = -1 }, item => | |
{ | |
Interlocked.Increment(ref level); | |
Trace.WriteLine(string.Format("in {0} {1}", item, | |
level)); | |
Stopwatch sw = Stopwatch.StartNew(); | |
while ((sw.Elapsed.TotalSeconds < TimeSpan.FromSeconds(Environment.ProcessorCount * 25).TotalSeconds)) | |
{ | |
} | |
Trace.WriteLine(string.Format( | |
"leaving {0} {1}", item, level)); | |
Interlocked.Decrement(ref level); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment