环境:
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都是数值类型,应该是跟位置没有关系的吧。