zoukankan      html  css  js  c++  java
  • 调试-----调试正在运行的多线程程序

     4 using namespace std;
     5 static int a = 1;
     6 
     7 void *thread0(void*) 
     8 { 
     9     while (1)
    10     {
    11         a++;
    12     }
    13     return (void*)0;
    14 }
    15 
    16 void *thread1(void*) 
    17 { 
    18     while (1)
    19     {
    20         a++;
    21     }
    22     return (void*)0;
    23 }
    24 
    25 int main()
    26 {
    27     pthread_t thread[2];
    28     pthread_create(&thread[0], NULL, thread0, NULL);
    29     pthread_create(&thread[1], NULL, thread1, NULL);
    30 
    31     for (int i = 0; i < 2; i++)
    32     {
    33         pthread_join(thread[i], NULL); 
    34     }
    35     while (1)
    36     {
    37         sleep(2);
    38         cout << "pthread_join is called, block, this not execute" << endl;
    39     }
    40     
    41     return 0;
    42 }

    main.cpp

    1. 运行上面的程序               ./main

    2. 查看进程号                     ps aux | grep main

    3. attach上去                    gdb  main   [进程号]

    4. 显示线程                        info  thread

    5. attach上一个线程            thread  3

    6. 设断点正常调试(不要输入run运行了, 因为程序已经启动了)

  • 相关阅读:
    Apache POI 示例
    使用wsimport生成webservice客户端代码
    监听器
    @WebFilter注解
    事务
    k8s的deployment应用
    k8s 组件架构
    使用kubeadm安装kubernetes1.12.1
    轻量级批量管理工具pssh
    使用Bind服务配置DNS服务器
  • 原文地址:https://www.cnblogs.com/helloweworld/p/4050784.html
Copyright © 2011-2022 走看看