C++11线程提升容器
C++11 thread boost container
一个带有C++11线程的简单代码:
#include <iostream>
#include <thread>
#include <string>
using namespace std;
void thread_task(){
std::cout<<"hello, here is thread task with state:"<<std::endl;
}
int main(int argc, char *argv[])
{
std::thread t(thread_task);
t.join();
return 0;
}
编译:
g++ -pthread -std=c++11 -O0 -Wall -g -ggdb main.cpp -o main -lboost_system -lboost_filesystem -lboost_serialization
./main can execute right!
--
g++ -pthread -std=c++11 -O0 -Wall -g -ggdb main.cpp -o main -lboost_system -lboost_filesystem -lboost_serialization -lboost_container-mt
g++ -pthread -std=c++11 -O0 -Wall -g -ggdb main.cpp -o main -lboost_system -lboost_filesystem -lboost_serialization -lboost_container
./main all will have an error:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
[1] 29643 abort (core dumped) ./main
为什么-lbox_container会导致此错误?当然,在我的代码示例中不需要boost_container。这不是一个例子。
这是的答案
g++ -Wl,--no-as-needed -pthread -std=c++11 -O0 -Wall -g -ggdb main.cpp -o main -lboost_system -lboost_filesystem -lboost_serialization -lboost_container
相关文章:
- 具有 C++11 多线程的特征库
- 为什么即使调用了析构函数,C++11 中的分离线程也可以执行
- C++11:具有互斥锁的线程看到原子变量的值发生变化,尽管这是唯一可以改变它的代码
- C++11:将矢量元素作为线程传递到线程函数中
- DirectX 11 -- Hello Triangle 未呈现 -- 原因:运行时库C++多线程
- 终止读取时阻止的线程 c++11
- C++11如何在1个线程中使用条件变量处理2个线程安全队列
- C++11 - 可以等待多个不同事件的线程?
- 将字符串指针传递到C++和Xcode 11.1中不同线程上运行的函数
- 多线程 C++11 应用程序中的同步
- std::线程与 pthread_setschedparam 与 C++ 11.
- C++ 11 thread_local和"外来"线程
- C++ 11 线程在分离后会自动销毁吗?
- Valgrind 检查简单多线程 C++11 得到 SIG11 错误
- Boost::线程 / C++11 std::thread,想要唤醒工作线程的条件
- c++将各种参数传递给父类构造函数(线程c++11)
- 线程c++11标准和Netbeans/其他IDE
- 多线程c++11-ish队列在windows上失败
- 在多线程c++ 11程序中,当异常未处理时会发生什么
- 分段故障多线程C++11