一 多线程需要的编译选型
g++ -std=c++11 hello.cpp -o hello -lpthread
如果不加-lpthread,则会碰到问题
/tmp/ccGd5Yww.o: In function `std::thread::thread<void (&)()>(void (&)())':
hello.cpp:(.text._ZNSt6threadC2IRFvvEJEEEOT_DpOT0_[_ZNSt6threadC5IRFvvEJEEEOT_DpOT0_]+0x21): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
二 线程启动
2.1 线程构造函数
有件事需要注意,当把函数对象传入到线程构造函数中时,需要避免“最令人头痛的语法解析”(C++’s most vexing parse,