This puzzle was presented at NDC 2010. There are links to video from there, but they are all broken. I don't understand the behavior of this program; why does it hang?
class Woot
{
private static float PI;
private static bool initialized = doInitialize();
private static bool doInitialize()
{
if (!initialized)
{
var thread = new Thread(() => { PI = 3.14f; });
thread.Start();
thread.Join(); // here
}
return true;
}
public static void Main(string[] args)
{
Console.WriteLine(PI);
}
}
What is the output of this program? Is it:
- 3.14
- 0
- Throws exception
- None of the above