Created
March 7, 2013 15:07
-
-
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.
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
Id collision! | |
task.Id == other.Id: True | |
task == other: False |
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
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