typedef struct
{int a;
char b[512];
}mystru;
UINT threadproc(LPVOID pParam)
{
mydlg *pDlg=(mydlg*)pParam;
mystru *stru_1=new mystru
memset(&stru,0,sizoef(stru));
stru->a=1;
stru->b="xmzq";
........
stru->a=1000;
stru->b="adfafafafafaf";
}void mydlg::start()
{
for(int i=0;i<5;i++)
{
AfxBeginThread(threadproc,(LPVOID)this);
} }请问执行start后,启动5个线程,5个线程里的结构变量会不会冲突,引起变量计算异常??????
{int a;
char b[512];
}mystru;
UINT threadproc(LPVOID pParam)
{
mydlg *pDlg=(mydlg*)pParam;
mystru *stru_1=new mystru
memset(&stru,0,sizoef(stru));
stru->a=1;
stru->b="xmzq";
........
stru->a=1000;
stru->b="adfafafafafaf";
}void mydlg::start()
{
for(int i=0;i<5;i++)
{
AfxBeginThread(threadproc,(LPVOID)this);
} }请问执行start后,启动5个线程,5个线程里的结构变量会不会冲突,引起变量计算异常??????
不会的,呵呵
mystru *stru_1=new mystru
这一步是不是再最后释放掉好一点?
每个线程都从所在的进程的4GB地址空间中分配了自己的栈。当使用
静态或者全局变量时,每个线程有同时访问这些变量,可能会破坏
变量的内容。然而,局部和自动变量,是创建在线程的栈上的,因此
不太可能被另一线程破坏。所以,在编写函数时,要尽量使用局部
或者自动变量,避免使用静态和全局变量。
typedef struct
{int a;
char b[512];
}mystru;
是全局变量啊。
{int a;
char b[512];
}mystru;只是类型,不是变量
你是用的new的变量