user3676367
user3676367

Reputation: 79

Does thread.join starts all threads at the same time

    Thread[] threads = new Thread[12];
    int temp;

    //_stopRequest = false;
    for (int i = 0; i < threads.Length - 1; i++)
    {
        temp = i;
        threads[temp] = new Thread(new ThreadStart(() => test(test1[temp],"start", temp)));
        threads[temp].Start();
        //threads[temp].Join();
    }

   for(int i=0; i<threads.Length-1; i++)
   {
     threads[i].Join();
   }

Can Anyone please explain me

Upvotes: 2

Views: 86

Answers (1)

Michael D
Michael D

Reputation: 678

No, the threads are started when you call Start().

If you would call Join() immediately after Start() (the commented-out code), each thread would be started and then execution of the current thread would be halted until the first thread stops. So it would actually have acted as a single thread.

The way the code is now, all threads are started and then the current thread waits for all the started threads to finish.

Upvotes: 3

Related Questions