Skip to content

Instantly share code, notes, and snippets.

@StephenCleary
Created March 7, 2013 15:07
Show Gist options
  • Save StephenCleary/5108676 to your computer and use it in GitHub Desktop.
Save StephenCleary/5108676 to your computer and use it in GitHub Desktop.
Task identifiers are not unique. On my machine, this program will run for 3 minutes and then produce the output.
Id collision!
task.Id == other.Id: True
task == other: False
using System;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
var task = new TaskCompletionSource<object>(null).Task;
var taskId = task.Id;
Task other;
do
{
other = new TaskCompletionSource<object>(null).Task;
if (other.Id == 0)
Console.WriteLine("Saw Id of 0!"); // (never executed)
} while (other.Id != task.Id);
Console.WriteLine("Id collision!");
Console.WriteLine(" task.Id == other.Id: " + (task.Id == other.Id));
Console.WriteLine(" task == other: " + (task == other));
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment