Cannot insert breakpoint 0.

94 篇文章 1 订阅
49 篇文章 0 订阅

环境:

Linux   GCC

问题:

134    int nRet=close(m_threadPool[pos]->sock);

(gdb) 
Warning:
Cannot insert breakpoint 0.
Error accessing memory address 0xaa8ce1d1: 输入/输出错误.

394        int nRecv=recv(sock, recvBuf, nBufSize, 0);
(gdb) 
Warning:
Cannot insert breakpoint 0.

Error accessing memory address 0xaa8ce1d1: 输入/输出错误.

但实际上,用"info break"命令查看断点信息,并没有断点0

代码如下:

结构体:

typedef struct threadInfo
{
    int sock;
    pthread_t threadID;
    char name[16];
}ThreadInfo, * pThreadInfo;
出问题的代码段:

    pthread_cancel(m_threadPool[pos]->threadID);
    close(m_threadPool[pos]->sock);

    //覆盖对应记录
    memcpy(m_threadPool[pos], m_threadPool[pos+1], (m_nCurrentNum-pos)*sizeof(ThreadInfo));
尝试:

实在没办法,做了如下尝试,即先把线程ID和sock取出来,覆盖对应记录,然后再进行关闭sock和关闭线程的处理

调试之后发现没有问题了

      pthread_t tempThread=m_threadPool[pos]->threadID;
      int sock=m_threadPool[pos]->sock;

      //覆盖对应记录
      memcpy(m_threadPool[pos], m_threadPool[pos+1], (m_nCurrentNum-pos)*sizeof(ThreadInfo));

      close(sock);
      pthread_cancel(tempThread);
原因:

不晓得为什么...按说,线程类型pthread_t 跟套接字类型int都是数值类型,应该是跟位置没有关系的吧。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值