Jump to content
  • Advertisement
Sign in to follow this  
Devil0150

C++ 11 thread not working on CodeBlocks

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

If you intended to correct an error in the post then please contact us.

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>
#include <thread>

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

int main()
{
    std::cout << "starting thread";
    std::thread thr1(foo);

    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 this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!