c++ 11 thread 初试
来源:互联网 发布:学生自杀数据 编辑:程序博客网 时间:2024/05/17 08:50
最新的 c++11标准整合进了 线程支持,下面写一个小程序测试一下。
测试代码:
#include <iostream>#include <thread>void hello(void){std::cout << "Hello concurrent world" << std::endl;}int main(void){std::thread t(hello);t.join();}
编译方法:
g++ -std=c++11 thread1.cpp -pthread -g -o thread
可见,还是需要 pthreads库支持。。
在 hello()加个断点,看一下此时的调用栈:
#0 hello () at thread1.cpp:6#1 0x08049b27 in std::_Bind_simple<void (*())()>::_M_invoke<>(std::_Index_tuple<>) (this=0x804e024) at /usr/include/c++/4.8/functional:1732#2 0x08049aad in std::_Bind_simple<void (*())()>::operator()() ( this=0x804e024) at /usr/include/c++/4.8/functional:1720#3 0x08049a62 in std::thread::_Impl<std::_Bind_simple<void (*())()> >::_M_run() (this=0x804e018) at /usr/include/c++/4.8/thread:115#4 0xb7f76d1e in ?? () from /usr/lib/i386-linux-gnu/libstdc++.so.6#5 0xb7e9ff70 in start_thread (arg=0xb7ca1b40) at pthread_create.c:312#6 0xb7dd6bee in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:129
可以看到, gcc 4.8里面, c++11的线程基本上是对 pthreads的封装。
我使用的 gcc版本是 4.8.2
0 0
- c++ 11 thread 初试
- C语言初试
- C++:创建线程初试
- Thread(C#)
- c thread
- thread.c
- 初试
- 初试
- 初试
- 初试
- c语言词法分析初试(C++实现)
- 2017.11.05 周日 初试linux c 体会
- something about thread(c#)
- linux + thread + c (一)
- C#Thread的使用
- 【c++】线程thread类
- c++thread学习(1)
- C++/MFC-线程Thread
- Linux编程基础之三——Linux文件管理操作
- PHP结合JAVA的开发技术 LAJP
- java 读取文件的方法大全
- Tomcat域名或IP地址访问方式配置方法
- 使用Struts2的拦截器和自定义注解方式实现权限控制
- c++ 11 thread 初试
- kotlin 学习之 HelloWorld
- csdn我又回来了
- java生成图片验证码显示在页面上
- 将本地git管理的eclipse adt项目引入android studio
- RPC中间件之Hessian
- JAVA中的反射只获取属性的get方法
- PIC单片机的时钟模式
- 2015年需要了解的前端框架和语言