Let’s say, that I have a program code like this:
#include <iostream>
#include <Windows.h>
#include <tbb/tbb.h>
void SomeFunction()
{
// do something
}
void MyThread(int arg)
{
std::cout << "This is a thread function\n" << std::endl;
for (int i = 0; i < 10000; i++)
{
arg++;
Sleep(1);
}
SomeFunction();
}
int main ()
{
tbb::tbb_thread pMyThread = tbb::tbb_thread(MyThread, 3);
pMyThread.join();
return 0;
}
From the above we can see that main() is calling MyThread() on a different thread pMyThread. And MyThread() is calling SomeFunction(). Now, will SomeFunction() (or any other function which is called by MyThread()) be executed on pMyThread too? Thanks.
Yes, any function call issued from a thread’s main function will exist on that thread’s private stack.