Marco
Marco

Reputation: 1025

What is the meaning of 'join' in thread (VC++2010)?

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

Answers (2)

eandersson
eandersson

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

XenKid
XenKid

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

link of ParameterizedThreadStart

Upvotes: 1

Related Questions