2 qq 17482331 qq_17482331 于 2016.04.07 20:43 提问

0x101bb6ca (msvcr100d.dll) 处有未处理异常

两个线程的服务器程序,当两个客户端对其发送数据时,提示:server35.exe 中的 0x101bb6ca (msvcr100d.dll) 处有未经处理的异常: 0xC0000005: 读取位置 0x0000000000000000 时发生访问冲突
贴出代码如下:
#include
#include
#include
#include "mysql.h"
#include
#include
#include
#include
using namespace std;
#pragma comment(lib,"WS2_32.lib")
#pragma comment(lib, "libmysql.lib")
#pragma comment(lib,"wsock32.lib")

#define F_PATH "e:\VS2010_Project\location\location.txt"
DWORD WINAPI myfun1(
LPVOID lpParameter
);
DWORD WINAPI myfun2(
LPVOID lpParameter
);
static SOCKET s1,s2;
/*static char sztext[100];
static FILE f1;
static sockaddr_in addr,addr2;
static char *p1,*p2;
static char a1[20],a2[20];
static MYSQL mysql;
/
static sockaddr_in addr,addr2;
char query[150];

int main()
{
WSADATA data;
WORD w=MAKEWORD(2,0);
//char sztext[40];
HANDLE h1,h2;
::WSAStartup(w,&data);
SOCKET s;
s=::socket(AF_INET,SOCK_STREAM,0);
//sockaddr_in addr,addr2;
int n=sizeof(addr2);
addr.sin_family=AF_INET;
addr.sin_port=htons(6000);
addr.sin_addr.S_un.S_addr=INADDR_ANY;
::bind(s,(sockaddr*)&addr,sizeof(addr));
::listen(s,5);
printf("服务器已经启动\r\n");
// f1=fopen("location.txt","w");
//mysql_init(&mysql);
while(true)
{
s1=::accept(s,(sockaddr*)&addr2,&n);
h1=::CreateThread(NULL,0,myfun1,NULL,0,NULL);
::Sleep(100);
//printf("有用户连入网络!\r\n");
s2=::accept(s,(sockaddr*)&addr2,&n);
h2=::CreateThread(NULL,0,myfun2,NULL,0,NULL);
::Sleep(100);
::CloseHandle(h1);
::CloseHandle(h2);
//printf("又有用户连入网络!\r\n");
}

::closesocket(s);
//::closesocket(s1);
::WSACleanup();
if(getchar())
{
return 0;
}
else
{
::Sleep(100);
}

}
DWORD WINAPI myfun1(LPVOID lpParameter)
{
static char sztext[100];
//static FILE *f1;
//static char *p1[10];
static char a1[20],a2[20];
static MYSQL mysql;
//char *p1=new char[10];

if(s1!=NULL&&strlen(sztext)==0)
{
printf("%s已经连接上\r\n",inet_ntoa(addr2.sin_addr));
}
//printf("%s已经连接上\r\n",inet_ntoa(addr2.sin_addr));
::recv(s1,sztext,sizeof(sztext),0);
printf("%s\n",sztext);
strtok(sztext,":");
//p1=strtok(NULL,":");
strcpy(a1,strtok(strtok(NULL,":"),","));
//strcpy(a1,strtok(p1,","));
strcpy(a2,strtok(strtok(strtok(NULL,":"),","),","));
// /*fprintf(f1,a1);
// fprintf(f1,",");
// fprintf(f1,a2);
// fprintf(f1,"\n");
mysql_init(&mysql);
if(!(mysql_real_connect(&mysql,"localhost","assking","1992110328","LBS",0,NULL,0)))
{
printf("Error connecting to database:%s\n",mysql_error(&mysql));
}
else
{
printf("Connected...\n");
}
sprintf(query,"insert into loca(LO,LA)values('%s','%s')",a1,a2);

if(mysql_query(&mysql, query)) //执行SQL语句
{
printf("Query failed (%s)\n",mysql_error(&mysql));
}
else
{
printf("Insert success\n");
}
mysql_close(&mysql);
::closesocket(s1);
return 0;
}
DWORD WINAPI myfun2(LPVOID lpParameter)
{

static char sztext[100];
//static FILE *f1;
//static char *p2[10];
static char a1[20],a2[20];
static MYSQL mysql;
//char *p2=new char[10];
if(s2!=NULL&&strlen(sztext)==0)
{
printf("%s已经连接上\r\n",inet_ntoa(addr2.sin_addr));
}
//printf("%s已经连接上\r\n",inet_ntoa(addr2.sin_addr));
::recv(s2,sztext,sizeof(sztext),0);
printf("%s\n",sztext);
strtok(sztext,":");
//p2=strtok(NULL,":");
//strcpy(a1,strtok(p2,","));
strcpy(a1,strtok(strtok(NULL,":"),","));
strcpy(a2,strtok(NULL,","));
// /*fprintf(f1,a1);
// fprintf(f1,",");
// fprintf(f1,a2);
// fprintf(f1,"\n");
// mysql_init(&mysql);
if(!(mysql_real_connect(&mysql,"localhost","assking","1992110328","LBS",0,NULL,0)))
{
printf("Error connecting to database:%s\n",mysql_error(&mysql));
}
else
{
printf("Connected...\n");
}
sprintf(query,"insert into loca(LO,LA)values('%s','%s')",a1,a2);

if(mysql_query(&mysql, query)) //执行SQL语句
{
printf("Query failed (%s)\n",mysql_error(&mysql));
}
else
{
printf("Insert success\n");
}
mysql_close(&mysql);
::closesocket(s2);
return 0;
}

2个回答

oyljerry
oyljerry   Ds   Rxr 2016.04.07 22:01

直接编译器调试对应错误的代码行数 一般是指针问题

qq_17482331
qq_17482331 运行的时候是不报错的,只有在两个客户端同时在线,向服务器发送消息时才会报错。
一年多之前 回复
qq_17482331
qq_17482331   2016.04.08 09:44

运行的时候是不报错的,只有在两个客户端同时在线,向服务器发送消息时才会报错。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!