Skip to content

Instantly share code, notes, and snippets.

@kumpera
Created August 11, 2014 18:21
Show Gist options
  • Save kumpera/c13b5d3e5451900a94f2 to your computer and use it in GitHub Desktop.
Save kumpera/c13b5d3e5451900a94f2 to your computer and use it in GitHub Desktop.
using System;
using System.Threading;
using System.Threading.Tasks;
class MainClass {
public static void Main (string [] args)
{
Test ();
}
public static void Test ()
{
const int tasksCount = 1000000;
var tCount = 0;
object o = new Object ();
lock (o) {
for (var i = 1; i < tasksCount; i++) {
Task.Factory.StartNew(() => {
lock (o) {
Interlocked.Increment (ref tCount);
}});
Console.WriteLine ("{0} {1}", i, tCount);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment