为什么在这部分代码complete
被缓存?
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
}
但在这部分不是吗?
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();
}