Why in this part of code complete
is cached?
static void Main()
{
bool complete = false;
var t = new Thread (() =>
{
bool toggle = false;
while (!complete) toggle = !toggle;
});
t.Start();
Thread.Sleep (1000);
complete = true;
t.Join(); // Blocks indefinitely
}
but in this part it isn't?
static void Main()
{
bool complete = false;
bool toggle = false;
var t = new Thread (() =>
{
while (!complete) toggle = !toggle;
});
t.Start();
Thread.Sleep (1000);
complete = true;
t.Join();
}