I want to learn thread using C++. I know C++ provide <thread><atomic><future><mutex>, etc to support multi-threading.
I use mingw32 with gcc 4.8.1
Firstly, I tried to use <thread>.But some errors like ''' 'std::this_thread' has not been declared ''' or ''' 'thread' is not a member of 'std' ''' occured. I refered to the <thread> and found this ->
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
So I defined those in my .cpp file(I ignored the redefined warning). But it doesnot work. Then I refered to some website like stackoverflow. I realize the errors might be the result of thread-model. Mine is win32. I am in China and now the network is bad and hard to re-install mingw from sourceforge to validate that. Can someone decribe why is that? Thank you.
Second, I use boost/thread.hpp instead.
// codes here
#include <iostream>
#include <boost/thread.hpp>
int main()
{
// use boost::thread
boost::thread hello(&print_hello);
hello.join();
cout << "hello thread over" << endl;
return 0;
}
*/
Sometimes, the compiler cannot stop. Some msg like ''' recursively required from 'struct boost::mpl::aux::gcd_aux<...> '''. Sometimes ''' undefined reference to `_Unwind_SjLj_Resume' '''. I compiled the boost with the same compiler i use now. Someone said ' -lgcc_s -Wl,-Bdynamic ' should be added but it doesnot work.
I want to know why the problem occured.
——————————Feel sorry for my long description. Hope for your suggestions and criticism also. Thank you.
I suggest to update your compiler and make sure you get posix threads (and preferably 64bit compiler if you have 64bit OS).
MinGW GCC uses libstdc++ port for its standard library, and this is Unix library working exclusively with posix threads. Nobody bothered to fix it to work with win32 threads.
@MiiNiPaa Thank you very much. I will try the wrapper and after several days I will re-compile/get mingw with POSIX thread-model. But I cannot understand my problem when use boost.