Reputation: 1025
I read my teacher's code, but I don't understand. Could anyone please tell me the join here mean?
AddTask ^task1 = gcnew AddTask();
AddTask ^task2 = gcnew AddTask();
AddTask ^task3 = gcnew AddTask();
// First Method
Thread ^thread1 = gcnew Thread ( gcnew ParameterizedThreadStart( task1, &AddTask::Add ) );
Thread ^thread2 = gcnew Thread ( gcnew ParameterizedThreadStart( task1, &AddTask::Add ) );
Thread ^thread3 = gcnew Thread ( gcnew ParameterizedThreadStart( task1, &AddTask::Add ) );
thread1->Start("First");
thread2->Start("Second");
thread3->Start("Third");
thread1->Join();
thread2->Join();
thread3->Join();
Upvotes: 0
Views: 323
Reputation: 26352
The Join function blocks the calling thread until a thread terminates, while continuing to perform standard COM and SendMessage pumping.
http://msdn.microsoft.com/en-us/library/95hbf2ta.aspx
Upvotes: 1
Reputation: 161
.Join pauses the thread or Blocks the calling thread until a thread terminates.
ParameterizedThreadStart means that there is a parameter used in the thread
thread1->Start("First"); //''as you see there is a parameter: First,Second,Third
thread2->Start("Second");
thread3->Start("Third");
//''The threads starts at the same time and terminate at the same time
thread1->Join();
thread2->Join();
thread3->Join();
link of ParameterizedThreadStart
Upvotes: 1