Leon Lambert <la******@inil.com> wrote:
Just as a side thought. I think it would have taken less time to test it
then to post this message to newgroup.
While that's true and I certainly encourage testing, there *is* a point
to asking questions even if you've tested them and think you know the
answer. Just because something works once doesn't mean it's guaranteed
to work. For instance, will the result of the following program always
be 10000? It has been every time I've run it, but it's far from
guaranteed to be.
using System;
using System.Threading;
class Test
{
static int count;
static void Main()
{
ThreadStart starter = new ThreadStart(IncrementCount100Times);
Thread[] threads = new Thread[100];
for (int i=0; i < threads.Length; i++)
{
threads[i] = new Thread(starter);
threads[i].Start();
}
for (int i=0; i < threads.Length; i++)
{
threads[i].Join();
}
Console.WriteLine (count);
}
static void IncrementCount100Times()
{
for (int i=0; i < 100; i++)
{
count++;
}
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too