I just decided to start playing with my shiny new GCC-4.4's std::thread, and... well... it kept segfaulting on me .
Admittedly I didn't RTFM, since TFM for C++0x is somewhat hard to find currently, and I assumed it's going to be very similar to boost::thread.
Code:
#include <thread>
#include <unistd.h>
void t() {
sleep(5);
}
int main() {
std::thread t1(&t);
std::thread t2(&t);
t1.join();
t2.join();
}
Anyone wants to venture a guess at what might be wrong?
Code:
cyberfish@cyberfish-desktop:/tmp$ g++-4.4 -g -std=gnu++0x a.cpp
cyberfish@cyberfish-desktop:/tmp$ gdb a.out
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu"...
(gdb) r
Starting program: /tmp/a.out
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x00007fa9de939fa7 in std::thread::_M_start_thread (this=0x7fffe6da40e0,
__b=DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece.
)
at /home/cyberfish/gcc_svn/gcc/build/x86_64-linux-gnu/libstdc++-v3/include/x86_64-linux-gnu/bits/gthr-default.h:682
#2 0x0000000000400e6c in thread<void (*)()> (this=0x7fffe6da40e0,
__f=0x400c0c <t()>)
at /opt/gcc/lib/gcc/x86_64-linux-gnu/4.4.0/../../../../include/c++/4.4.0/thread:134
#3 0x0000000000400c38 in main () at a.cpp:10
(gdb) l
1 #include <thread>
2
3 #include <unistd.h>
4
5 void t() {
6 sleep(5);
7 }
8
9 int main() {
10 std::thread t1(&t);
(gdb)
Thanks