How to block new threads until all threads are created and started
I am building a small application simulating a horse race in order to gain
some basic skill in working with threads.
My code contains this loop:
for (int i = 0; i < numberOfHorses; i++)
{
horsesThreads[i] = new Thread(horsesTypes[i].Race);
horsesThreads[i].Start(100);
}
In order to keep the race 'fair', I've been looking for a way to make all
newly created threads wait until the rest of the new threads are set, and
only then launch all of them to start running their methods (Please note
that I understand that technically the threads can't be launched at the
'same time')
So basically, I am looking for something like this:
for (int i = 0; i < numberOfHorses; i++)
{
horsesThreads[i] = new Thread(horsesTypes[i].Race);
}
Monitor.LaunchThreads(horsesThreads);
No comments:
Post a Comment