boost::thread简介和gdb调试线程
来源:互联网 发布:淘宝网美都袋鼠皮相 编辑:程序博客网 时间:2024/05/21 03:56
File:
#include <boost/thread/thread.hpp>
class thread{public: class attributes; // EXTENSION thread() noexcept; thread(const thread&) = delete; thread& operator=(const thread&) = delete; thread(thread&&) noexcept; thread& operator=(thread&&) noexcept; ~thread(); template <class F> explicit thread(F f); template <class F> thread(F &&f); template <class F,class A1,class A2,...> thread(F f,A1 a1,A2 a2,...); template <class F, class ...Args> explicit thread(F&& f, Args&&... args); template <class F> explicit thread(attributes& attrs, F f); // EXTENSION template <class F> thread(attributes& attrs, F &&f); // EXTENSION template <class F, class ...Args> explicit thread(attributes& attrs, F&& f, Args&&... args); // move support thread(thread && x) noexcept; thread& operator=(thread && x) noexcept; void swap(thread& x) noexcept; class id; id get_id() const noexcept; bool joinable() const noexcept; void join(); template <class Rep, class Period> bool try_join_for(const chrono::duration<Rep, Period>& rel_time); // EXTENSION template <class Clock, class Duration> bool try_join_until(const chrono::time_point<Clock, Duration>& t); // EXTENSION void detach(); static unsigned hardware_concurrency() noexcept; typedef platform-specific-type native_handle_type; native_handle_type native_handle(); void interrupt(); // EXTENSION bool interruption_requested() const noexcept; // EXTENSION#if defined BOOST_THREAD_USES_DATETIME bool timed_join(const system_time& wait_until); // DEPRECATED template<typename TimeDuration> bool timed_join(TimeDuration const& rel_time); // DEPRECATED static void sleep(const system_time& xt);// DEPRECATED#endif#if defined BOOST_THREAD_PROVIDES_THREAD_EQ bool operator==(const thread& other) const; // DEPRECATED bool operator!=(const thread& other) const; // DEPRECATED#endif static void yield() noexcept; // DEPRECATED};void swap(thread& lhs,thread& rhs) noexcept;//具体提供的接口可以参考boost参考文档
namespace boost {
class thread;
class thread_group;
}
从名字可以看出来,thread为封装线程使用的对象,thread_group为线程组使用的对象
简单举例说明:
void Run(){prctl(PR_SET_NAME,(unsigned long)"yx");cout<<"thread:yx"<<endl; sleep(100);}
boost::thread th(Run);th.join();
yixiao@yixiao-p6-1319cx:/proc/2840$ ps -ef|grep -i a.out|grep -v grep
yixiao 3186 2101 0 22:05 pts/1 00:00:00 ./a.out
yixiao@yixiao-p6-1319cx:/proc/3186$ ps -L -p 3186
PID LWP TTY TIME CMD
3186 3186 pts/1 00:00:00 a.out
3186 3187 pts/1 00:00:00 yx
thread_group的使用也较为简单:
void Run1(){prctl(PR_SET_NAME,(unsigned long)"yx_1");cout<<"thread:yx_1"<<endl; sleep(100);}
boost::thread_group gp;gp.create_thread(Run);gp.add_thread(new boost::thread(Run1));gp.join_all();
yixiao 3552 2101 0 22:10 pts/1 00:00:00 ./a.out
yixiao@yixiao-p6-1319cx:/proc/3186$ ps -L -p 3552
PID LWP TTY TIME CMD
3552 3552 pts/1 00:00:00 a.out
3552 3553 pts/1 00:00:00 yx
3552 3554 pts/1 00:00:00 yx_1
gdb调试线程:
基本命令:
info threads --显示当前可调试的所有进程
thread ID --切换当前调试的线程为指定ID的线程
thread apply ID1 ID2 command --让一个或多个线程执行GDB的命令command
thread apply all command --让所有被调试线程执行GDB命令command
set scheduler-locking off|on|step
-off 不锁定任何进程,所有线程都执行
-on 只有当花钱被调试程序会执行
-step 在单步的时候,除了next过一个函数的情况外,只有当前线程会执行
(gdb) info threads
Id Target Id Frame
3 Thread 0x7ffff65d0700 (LWP 3696) "a.out" 0x00007ffff73df3c1 in clone () from /lib/x86_64-linux-gnu/libc.so.6
* 2 Thread 0x7ffff6dd1700 (LWP 3695) "a.out" Run () at test_thread.cc:10
1 Thread 0x7ffff7fdf740 (LWP 3692) "a.out" 0x00007ffff73df3c1 in clone () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) thread 2
[Switching to thread 2 (Thread 0x7ffff6dd1700 (LWP 3695))]
#0 Run () at test_thread.cc:10
10 prctl(PR_SET_NAME,(unsigned long)"yx");
(gdb) thread apply all continue
Thread 3 (Thread 0x7ffff65d0700 (LWP 3696)):
Continuing.
thread:yx
Breakpoint 1, Run1 () at test_thread.cc:17
17 prctl(PR_SET_NAME,(unsigned long)"yx_1");
Thread 2 (Thread 0x7ffff6dd1700 (LWP 3695)):
Continuing.
- boost::thread简介和gdb调试线程
- boost::thread线程管理
- boost::thread线程管理
- boost::thread线程管理
- gdb调试工具简介
- gdb调试工具简介
- gdb调试工具简介
- boost::thread编程-线程创建
- boost::thread编程-线程中断
- boost::thread编程-线程组
- boost::thread编程-线程中断
- Boost Thread 编程指南、Boost线程入门教程
- gdb调试死锁线程
- gdb调试线程
- gdb调试线程锁
- 【Boost】boost库中thread多线程详解11——线程的休眠和中断
- arm下gdb调试和杀线程以及make编译
- 使用gdb调试程序简介
- jsp页面中当新闻标题文字过长时用“...”省略号表示
- 【Cracking the coding interview】Q1.8(旋转字符串)
- java基础(六)-----浅谈java中“==”和“equals”的区别
- Android禁止屏幕旋转和重启Activity
- 4种编程语言基本数据类型及其取值范围整理(C++,Java,Python,Go)
- boost::thread简介和gdb调试线程
- Android-Fragments的使用
- 学习C++ 1
- UVA - 12260 Free Goodies
- Linux命令:tar
- 同步化,同步,异步化,异步操作的区别
- Ubuntu上搭建Hadoop环境(单机模式+伪分布模式)
- C函数中,可变长参数的传递?
- stm32 串口发送数据第一字节丢失