我的线程加载资源时常没有加载成功.有时后,加载又成功.不用线程,就一定成功.我在程序在做延迟处理,程序打开4S后,才读取线程,但还是出错,原因不明.我也没有在构造函数中,使用线程.
#include"ENthread.h"int ENthread::ENCreateThread(unsigned long& t, void(__cdecl *func)(void *), void* arglist)
{
cout<<"创建线程:func:"<<func<<endl;
return t = (unsigned long)_beginthread(func, 0, arglist);
} void ENthread::ENExitThread()
{
cout<<"结束线程"<<endl;
_endthread();}使用:
if(ENd3dOb->ENtimeOb->getSecond()>=m_game->GAParameterOb->ParDouble[49])
{
percent=1;
static int OFF=0;
if(OFF==0)
{
OFF=1;
unsigned long t;
ENthread::ENCreateThread(t,GALoading::LoadingThread, m_game);
}
}
//加载资源
void GALoading::LoadingThread(void *p)//加载游戏资源
{
m_game->GAMainOb->PublicResourceIni();//一次性加载资源
m_game->GAMainOb->GAMainIni();
m_game->GAMessageOb->GAMessageIni(); cout<<"资源读完"<<endl;
percent=1000;
if(percent==1000)
{
ENthread::ENExitThread();
}
}
#include"ENthread.h"int ENthread::ENCreateThread(unsigned long& t, void(__cdecl *func)(void *), void* arglist)
{
cout<<"创建线程:func:"<<func<<endl;
return t = (unsigned long)_beginthread(func, 0, arglist);
} void ENthread::ENExitThread()
{
cout<<"结束线程"<<endl;
_endthread();}使用:
if(ENd3dOb->ENtimeOb->getSecond()>=m_game->GAParameterOb->ParDouble[49])
{
percent=1;
static int OFF=0;
if(OFF==0)
{
OFF=1;
unsigned long t;
ENthread::ENCreateThread(t,GALoading::LoadingThread, m_game);
}
}
//加载资源
void GALoading::LoadingThread(void *p)//加载游戏资源
{
m_game->GAMainOb->PublicResourceIni();//一次性加载资源
m_game->GAMainOb->GAMainIni();
m_game->GAMessageOb->GAMessageIni(); cout<<"资源读完"<<endl;
percent=1000;
if(percent==1000)
{
ENthread::ENExitThread();
}
}
解决方案 »
- 代码写迷糊的后果
- 在view里进行文本编辑
- 如何将结构化值保存到Blob字段
- 在WIN32 Dynamic-Link Library建了一个工程,为什么在里面不能用CTime类,请高手指教!!!!
- 先散1000分,抗议某些人滥用职权!!!(4)
- 怎样得到当前日期加上100天的日期??
- 我现在用 VC编写一个类似示波器的界面,现在想通过该界面实时显示采集到的波形,请问我该如何决定X坐标的值,即占空比
- 问一下:医学图像如何转换成bmp文件格式?
- 如何在对话框应用程序中加入,工具条和菜单?(我只能给这么多了)
- 我要学习 WIN 下的汇编,从哪里开始呀,什么书好!(DOS下的刚学完)
- 关于编译器设置的问题 来者有分
- 求MCDBURNER C++源码
m_game->GAMainOb->GAMainIni();
m_game->GAMessageOb->GAMessageIni();
这些语句根本没有考虑并发访问的加锁问题,当然也可能无需加锁,取决于你的实现。断点跟踪一下吧。
Static_ENd3dOb=ENd3dOb;
// GALoadingOnEnter_1();
// static unsigned long t=3333;
// ENthread::ENCreateThread(t,GALoading::LoadingThread, Static_m_game);
static unsigned long t;
_beginthreadex(0,t,&LoadingThread,(unsigned int *)Static_m_game,0,0);
cout<<"GALoading::OnEnter(void)"<<endl;unsigned int __stdcall GALoading::GALoadingOnEnter_1(void *param)
{
// CRITICAL_SECTION *tempSysCrs=ENd3dOb->getCriticalSection();//临界区
CRITICAL_SECTION *tempSysCrs=Static_ENd3dOb->getCriticalSection();//临界区
EnterCriticalSection(tempSysCrs);//临界区 char ss[100]="";
char ss1[100]="";
char ss2[100]="";
int v=5;
percent=2;
Static_ENd3dOb->ENresourceOb->ENImageBMPIni("resource\\public\\resource-1.bmp","PIC-1");
CountResource++;
percent=20;
Static_ENd3dOb->ENresourceOb->ENImageBMPIni("resource\\public\\resource-2.bmp","PIC-2");
CountResource++;
Static_ENd3dOb->ENresourceOb->ENImageBMPIni("resource\\public\\resource-3.bmp","PIC-3");
CountResource++;
Static_ENd3dOb->ENresourceOb->ENImageBMPIni("resource\\public\\resource-4.bmp","PIC-4");
CountResource++;
Static_ENd3dOb->ENresourceOb->ENImageBMPIni("resource\\public\\resource-4a.bmp","PIC-5");
CountResource++;
Static_ENd3dOb->ENresourceOb->ENImageBMPIni("resource\\public\\resource-1a.bmp","PIC-6");
CountResource++;
// ENd3dOb->ENresourceOb->ENImageBMPIni("resource\\public\\resource-2a.bmp","PIC-7");
// CountResource++;
/*
strcpy(ss,"PIC-3");//大图纹理缓冲区名(纹理图)
ENd3dOb->ENresourceOb->ENImageBMPIni("resource\\public\\plane-1.bmp",ss);
CountResource++;
strcpy(ss1,"PIC-4");//大图纹理缓冲区名(a图)
ENd3dOb->ENresourceOb->ENImageBMPIni("resource\\public\\plane-1a.bmp",ss1);
CountResource++;
*/
/*
for(int i=5;i<200;i++)
{
_stprintf(ss,"PIC-%d",i);
ENd3dOb->ENresourceOb->ENImageBMPIni("state\\GALoading\\3.bmp",ss);
}
*/
Static_m_game->GAMainOb->PublicResourceIni();//一次性加载资源
Static_m_game->GAMainOb->GAMainIni();
Static_m_game->CompanyLogoOb->CompanyLogoIni();
Static_m_game->BackGroundOb->BackGroundIni();
Static_m_game->GAMessageOb->GAMessageIni();
LeaveCriticalSection(tempSysCrs);
// LeaveCriticalSection(&tempSysCrs1); cout<<"资源读完"<<endl;
percent=1000;
if(percent==1000)
{
// ENthread::ENExitThread();
cout<<"退出线程1:"<<percent<<endl;
_endthreadex(0);
cout<<"退出线程2:"<<percent<<endl;
}
return 0;
}
http://topic.csdn.net/u/20100116/12/7c711b81-1786-4fb9-975d-ea805325edce.html