线程中的'join'是什么意思(VC ++ 2010)?

时间:2012-03-25 17:59:51

标签: multithreading visual-c++ c++-cli

我读了老师的代码,但我不明白。谁能告诉我这里的加入意味着什么?

    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();

2 个答案:

答案 0 :(得分:1)

Join函数阻塞调用线程,直到线程终止,同时继续执行标准COM和SendMessage抽取。

http://msdn.microsoft.com/en-us/library/95hbf2ta.aspx

答案 1 :(得分:1)

.Join暂停线程或阻塞调用线程,直到线程终止。

ParameterizedThreadStart表示在线程中使用了一个参数

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 thread->Join

link of ParameterizedThreadStart