score:1

Accepted answer

seems like linking with the pthread library is missing. add "pthread" under build->settings->tool settings->gcc c++ linker->libraries.

this is what my build log says:

**** build of configuration debug for project testpthreads ****

make all 
building file: ../main.cpp
invoking: gcc c++ compiler
g++ -o0 -g3 -wall -c -fmessage-length=0 --std=c++0x -pthread -mmd -mp -mf"main.d" -mt"main.d" -o "main.o" "../main.cpp"
finished building: ../main.cpp

building target: testpthreads
invoking: gcc c++ linker
g++  -o "testpthreads"  ./main.o   -lpthread
finished building target: testpthreads

your code then works and outputs:

launched by thread launched by thread launched by thread 1
launched by thread 0
launched by thread 2
launched by thread 9
launched by thread 3
launched by thread 7
launched by thread 6
4
launched by thread 8
5

i get the same error as you without -lpthread

my linker settings: linkersettings


Related Query

More Query from same tag