void ThreadFn(int& i)
{
cout<<"Hi from thread "<<i<<endl;
}
int x = 0;
void CreateThreads(vector<thread>& workers)
{
for(int i = 0; i< 10; i++)
{
workers.push_back(thread(&ThreadFn, x));
}
}
I was expecting a compilation error in the thread creation (workers.push_back(thread(&ThreadFn, x));
) since x
should be passed by ref.
I though the right syntax should've been:
workers.push_back(thread(&ThreadFn, std::ref(x)));
Of course, the code compiles fine and also behaves properly. I am using VC11
. Any idea why this isn't being flagged?