mercredi 19 mai 2021

Compiling std::thread in CodeBlocks

I'm trying to run this simple code just to test some threading in C++

#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;
}

Upon compiling it with GNU GCC compiler I get this error.

||=== Build: Debug in ThreadingPractice (compiler: GNU GCC Compiler) ===| C:\Users\X\Documents\ThreadingPractice\main.cpp||In function 'int main()':| C:\Users\X\Documents\ThreadingPractice\main.cpp|15|error: 'thread' is not a member of 'std'| C:\Users\X\Documents\ThreadingPractice\main.cpp|16|error: 't' was not declared in this scope| C:\Users\X\Documents\ThreadingPractice\main.cpp|14|warning: unused variable 'f' [-Wunused-variable]| ||=== Build failed: 2 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|

Some looking around seems to indicate that GCC does not support all of threads. If this is the case can anyone bring to my attention which compiler does allow for it? Otherwise I would appreciate any help on how to compile this code.

I am on Windows and have "-std=c++11" enabled. This is also the latest build of ColdBlocks. Thanks for your time.

Aucun commentaire:

Enregistrer un commentaire