using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Collections.ObjectModel;
using System.Threading;
namespace JUSTFORPRACTICE
{
class Program
{
static int total = 0;
public static void Main()
{
Thread t1 = new Thread(fun);
t1.Start();
Thread t2 = new Thread(fun);
t2.Start();
Thread t3 = new Thread(fun);
t3.Start();
t1.Join();
t2.Join();
t3.Join();
Console.WriteLine(total);
}
public static void fun()
{
for (int i = 1; i <= 10000; i++)
total++;
}
}
}
I've read that using Join()
we can prevent the main thread from executing the futher statements until the current thread in running.But here each time when I am running i m getting different output.....Why?