I am trying to add a simple for loop with threads, yet still something is not working out. I've checked a number of reasons and I cannot find any solution to that.
I have a simple class with two methods A() and B(). From the other class, I'm calling method A(). This is how it looks:
void MyClass::A()
{
std::vector<std::thread> threads;
for(int i=0;i<2;i++)
{
threads.push_back(std::thread(&MyClass::B, this));
}
for(auto &t : threads)
{
if(t.joinable())
t.join();
}
}
void MyClass::B()
{
}
And yet I am still receiving some errors:
#0 ?? ?? () (??:??)
#1 00446D62 pthread_create_wrapper () (??:??)
#2 75327FB0 msvcrt!_cexit() (C:\Windows\SysWOW64\msvcrt.dll:??)
#3 040C8710 ?? () (??:??)
#4 753280F5 msvcrt!_beginthreadex() (C:\Windows\SysWOW64\msvcrt.dll:??)
#5 75B17C04 KERNEL32!BaseThreadInitThunk() (C:\Windows\SysWOW64\kernel32.dll:??)
#6 77ABAB8F ?? () (??:??)
#7 77ABAB5A ?? () (??:??)
#8 ?? ?? () (??:??)
Does someone have any idea what is wrong?
Just to add one more thing. This:
void MyClass::A()
{
std::thread t(&MyClass::B, this);
if(t.joinable())
t.join();
}
void MyClass::B()
{
}
works without any problems.
mainfunction and appropriate includes works without problem on linux. Suggest you post full MCVE as also suggested by SergeyA.