次の短いプログラムを検討してください。
#include <thread>
int Foo() {
while (1);
}
int main(){
std::thread t(Foo);
std::thread s(Foo);
// (std::thread(Foo));
t.join();
}
これは、コンパイルして実行します (永久に)。
g++ -Wl,--no-as-needed DoubleBufferTest.cc -o DoubleBufferTest -std=c++0x -pthread
コメントアウトされた行では、ここで説明されている手法を使用して、新しいスレッドを匿名で宣言しようとしています。ただし、その行がコメントインされると、コンパイルできますが、実行すると次のエラーが発生します。
terminate called without an active exception
Aborted (core dumped)
スレッドを匿名で正しく宣言するにはどうすればよいですか?
注意してください、私はにいg++ 4.4.7
ます。