Ok so i tried copying the threading example to code blocks and it didnt work, i checked the 2 boxes in the build options for using c++11 but it still doesnt work. what else does i need to do? also can you explain threading a little bit more to me im a bit confused, i read that its used to execute process on 2 different threads so im guessing that makes performance better but im not sure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream> // std::cout
#include <thread> // std::thread
void foo()
{
// do stuff...
}
void bar(int x)
{
// do stuff...
}
int main()
{
std::thread first (foo); // spawn new thread that calls foo()
std::thread second (bar,0); // spawn new thread that calls bar(0)
std::cout << "main, foo and bar now execute concurrently...\n";
// synchronize threads:
first.join(); // pauses until first finishes
second.join(); // pauses until second finishes
std::cout << "foo and bar completed.\n";
return 0;
}
|
errors
||=== C++ threading, Debug ===|
C:\Users\Chay Hawk\Desktop\C++ threading\main.cpp||In function 'int main()':|
C:\Users\Chay Hawk\Desktop\C++ threading\main.cpp|16|error: 'thread' is not a member of 'std'|
C:\Users\Chay Hawk\Desktop\C++ threading\main.cpp|16|error: expected ';' before 'first'|
C:\Users\Chay Hawk\Desktop\C++ threading\main.cpp|17|error: 'thread' is not a member of 'std'|
C:\Users\Chay Hawk\Desktop\C++ threading\main.cpp|17|error: expected ';' before 'second'|
C:\Users\Chay Hawk\Desktop\C++ threading\main.cpp|22|error: 'first' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\C++ threading\main.cpp|23|error: 'second' was not declared in this scope|
||=== Build finished: 6 errors, 0 warnings (0 minutes, 4 seconds) ===|