Originally Posted by
Salem
Can you post your test case?
this was my actual test case
Code:
#include <iostream>
#include <thread>
#include <vector>
#include <memory>
std::mutex mutex;
int mutexProtected = 0;
void threadProc()
{
for (int i = 0; i < 5; ++i)
{
std::lock_guard<std::mutex> lock(mutex);
std::cout << "Value: " << ++mutexProtected << std::endl;
}
}
int main()
{
std::vector<std::shared_ptr<std::thread> > threadVector;
for (int i = 0; i < 20; ++i)
{
threadVector.push_back(std::shared_ptr<std::thread>(new std::thread(threadProc)));
}
for (auto& thread : threadVector)
{
thread->join();
}
return 0;
}
my compile command is
Code:
g++ -pthread -std=c++0x -c main.cpp
and the output I get on mingw is
Code:
main.cpp:6:1: error: 'mutex' in namespace 'std' does not name a type
main.cpp: In function 'void threadProc()':
main.cpp:13:2: error: 'lock_guard' is not a member of 'std'
main.cpp:13:18: error: 'mutex' is not a member of 'std'
main.cpp:13:35: error: 'mutex' was not declared in this scope
main.cpp:13:40: error: 'lock' was not declared in this scope
main.cpp: In function 'int main()':
main.cpp:22:33: error: 'thread' is not a member of 'std'
main.cpp:22:33: error: 'thread' is not a member of 'std'
main.cpp:22:44: error: template argument 1 is invalid
main.cpp:22:46: error: template argument 1 is invalid
main.cpp:22:46: error: template argument 2 is invalid
main.cpp:22:60: error: invalid type in declaration before ';' token
main.cpp:26:15: error: request for member 'push_back' in 'threadVector', which is of non-class type 'int'
main.cpp:26:41: error: 'thread' is not a member of 'std'
main.cpp:26:41: error: 'thread' is not a member of 'std'
main.cpp:26:52: error: template argument 1 is invalid
main.cpp:26:58: error: expected type-specifier
main.cpp:26:58: error: expected ')'
main.cpp:29:25: error: no matching function for call to 'begin(int&)'
more errors snipped...
even a simple test case like this exhibits essentially the same behavior
Code:
#include <mutex>
int main()
{
std::mutex mutex;
return 0;
}
there were many more errors, but they were all related to the compiler's inability to find a begin() or end() function for std::vector<std::shared_ptr<std::thread> >.
after more digging, I determined that on ubuntu, modifying the code to include <mutex> solved the problem. it seems that <mutex> was included implicitly by <thread> in g++ 4.6.3 on fedora 15, and a recent move to ubuntu 12.10 (gcc 4.7.3) for my main dev machine exposed that fact.
on mingw (gcc 4.7.3), including <mutex> did not solve the problem. it appears that the std::thread implementation in the official release of mingw version of g++ 4.7.3 is incomplete or nonexistent.