I want to assign value to att = 5
in thread t
. In the main thread
, I want to check if att
has been assigned to 5 yet
When I run the void check()
, the output is always 3
. Why is this?
class Program
{
static int att = 3;
static void Main(string[] args)
{
Thread t = new Thread(() => set(att));
t.Start();
check();
}
static void set(int para)
{
para = 5;
}
static void check()
{
while (att != 5)
{
Console.WriteLine(att);
}
Console.WriteLine(att);
}
}