I am trying Mono/.Net 3.5 under Linux (Ubuntu). I tried to use threads in Mono, but it doesn’t seem to work properly.
public static void Main (string[] args)
{
Thread thread =new Thread(()=> fn("first"));
Thread thread1=new Thread(()=> fn("second"));
thread.Start();
thread1.Start();
}
static void fn(string name)
{
for(int i=0;i<10;i++)
Console.WriteLine(i+" "+name);
}
Both loops run sequentially, as if I am not using threads.
What is wrong?
Running this on Windows, most of the time all the first thread’s writes happen before the second thread’s.
The loop is too trivial to really see the effects of multiple threads running concurrently. The first thread may simply finish before the second starts.
Try putting a Sleep or spin loop in the main loop.
or