I am learning to use threading so I am trying to run code utilizing the thread class so that I can run functions concurrently. However, trying to compile it in the terminals terminal, it says that thread and its object t1 is not declared.
I thought g++ doesn't support it but I also include in its argument to support c++11
image of the compiling command line
Any idea what I should I do about this error?
Code is provided below(an example from a website):
#include <string>
#include <iostream>
#include <thread>
using namespace std;
// The function we want to execute on the new thread.
void task1(string msg)
{
cout << "task1 says: " << msg;
}
int main()
{
// Constructs the new thread and runs it. Does not block execution.
thread t1(task1, "Hello");
// Do other things...
// Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution.
t1.join();
}
Aucun commentaire:
Enregistrer un commentaire