I compiled & installed gcc4.4 using macports.
When I try to compile using -> g++ -g -Wall -ansi -pthread -std=c++0x main.cpp...:
#include <thread> ... std::thread t(handle); t.join(); ....
The compiler returns:
cserver.cpp: In member function 'int CServer::run()': cserver.cpp:48: error: 'thread' is not a member of 'std' cserver.cpp:48: error: expected ';' before 't' cserver.cpp:49: error: 't' was not declared in this scope
But std::cout <<...
compiles fine..
Can anyone help me?
std::this_threadThis namespace groups a set of functions that access the current thread.
std::thread::operator= thread objects cannot be copied (2).
std::thread::join. Blocks the current thread until the thread identified by *this finishes its execution. The completion of the thread identified by *this synchronizes with the corresponding successful return from join() .
To use the MinGW-w64 with Win32 native threads you can install the mingw-std-threads headers. As described on that page, this is because MinGW-w64 is a port of GCC, but GCC does not include any native thread support.
gcc does not fully support std::thread yet:
http://gcc.gnu.org/projects/cxx0x.html
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html
Use boost::thread in the meantime.
Edit
Although the following compiled and ran fine for me with gcc 4.4.3:
#include <thread> #include <iostream> struct F { void operator() () const { std::cout<<"Printing from another thread"<<std::endl; } }; int main() { F f; std::thread t(f); t.join(); return 0; }
Compiled with
g++ -Wall -g -std=c++0x -pthread main.cpp
Output of a.out
:
Printing from another thread
Can you provide the full code? Maybe there's some obscure issue lurking in those ...
s?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With