得到这个问题 - 在标题..
我有这个代码:
#include <thread>
#include <iostream>
void my_thread_func()
{
std::cout<<"hello"<<std::endl;
}
int main()
{
std::thread t(my_thread_func);
t.join();
}
Run Code Online (Sandbox Code Playgroud)
从网站的某个地方.编译器选项-pthread -std = gnu ++ 0x(也试过-std = c ++ 0x)我有段错误.一切都在vmBox上的Debian上.我之前已经启动了其他代码,并且他们工作了.突然间,我在所有正在运行的应用程序中使用std :: thread进行了线程段错误.
编辑:这是来自gdb:
(gdb) where
#0 0x00000000 in ?? ()
#1 0x08048dc9 in thread<void (*)()> (this=0xbffff3fc,
__f=0x8048b9f <my_thread_func()>) at /usr/include/c++/4.4/thread:129
#2 0x08048bea in main () at ../test.cpp:18
Run Code Online (Sandbox Code Playgroud)
(当我用std :: thread t(&ClassName :: my_thread_func,ptr)启动更高级的应用程序时,错误是相同的,但是其他行[thread:133])
我正在网上搜索,但我没有找到合适的东西.
我正在使用pthreads处理一些多线程代码.当我发现一些内存泄漏(通过valgrind)时,我只是添加了一些内存泄漏
cout << " new [some name of class for me]" << endl;
Run Code Online (Sandbox Code Playgroud)
在构造函数的一部分,因为我以为我已经删除了所有这些.这表明它们中的一部分是在main()之前启动的.我已从main()中删除了所有内容,因此它看起来像:
int main(){
return 0;
}
Run Code Online (Sandbox Code Playgroud)
即使没有任何#includes,仍然会调用这些构造函数.我认为在这种情况下应该调用前面代码中的任何内容.我在eclipse中使用了"project clean"选项并尝试删除二进制文件(Debug/Release).什么都没有帮助..
那是什么意思?我还能做什么?提前致谢.