Public Group

C++ 11 thread not working on CodeBlocks

This topic is 2055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I wanted to try out the new std::thread in C++11 in Code Blocks and I'm not sure if I'm doing it right.

This is the code:

#include <iostream>

void foo()
{
std::cout << "\n thread started. \n";
}

int main()
{

std::cout << "waiting for thread to finish\n";
thr1.join();

std::cout << "done!\n";
return 0;
}



At first I got some kind of warning that I had to use a compiler flag (-std=c++11), so I did.

And now I get 'thread is not a member of std'

I'm using GNU GCC compiler on windows 7. What should I do?

Share on other sites
Works for me. What version of GCC do you have?

Share on other sites

I'm guessing that you're using MinGW, which as far as I know doesn't support C++11's threading yet.

Share on other sites

Yes I'm using MinGW. I didn't know it doesn't suport c++11 threading yet. I'll try something else. Thanks

Share on other sites
If you use the GCC that comes bundled with Code::Blocks (TDM) then it does not support threads. Tthere are MinGW builds that do support thread. Maybe try a nightly build or something more up-to-date than what C::B ships packaged.

Share on other sites

Ok I'll try the latest one I can find on the MinGW website.

Share on other sites

I've encountered the same problem, and decided to implement the basic features of std::thread/std::mutex. You can use it yourself, the link is below. This small library has also features, i.e. read-write mutexes and semaphores implemented on Windows and POSIX. It isn't something complicated nor difficult to implement yourself, but saves some time.

http://ubuntuone.com/6rLDt59Gl8GWc6wgZsG3Nh

Share on other sites
I think clang implements all of c++11 now, but I am not sure if it applies for Windows too. Still, it is good to check it out!

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• Forum Statistics

• Total Topics
633756
• Total Posts
3013709
×