多线程在DEBUG下运行结果正常,但是在Realese下运行不正常。请,谢谢

多线程在DEBUG下运行结果正常,但是在Realese下运行不正常。请高手指点,多谢。
有下面这样一个程序,在Debug下可以执行到Afxmessagebox( "执行成功 ");   ,但是在Release版本下运行不到。在while内死循环。
不知道为什么m_db-> f_fthread   =   TRUE;这句话不起作用。希望高手指点一二。

#include   "main.h "

typedef   struct{
        BOOL   f_fthread;
}T_DbInsert;

class   CTestDlg   :   public   CDialog
{
    public:
    {
          T_DbInsert   DbInsert1;
          T_DbInsert   DbInsert2;
          HANDLE   thread1;
          HANDLE   thread2;
          static   DWORD   WINAPI   InsertThread1(lpvoid   LpParamter);
    }
}

#include   "main.cpp "

DWORD   WINAPI   InsertThread1(lpvoid   LpParamter)
{
    T_DbInsert   *   m_db   =   (T_DbInsert*)LpParamter;
    m_db-> f_fthread   =   TRUE;
    return   0;
}

DWORD   WINAPI   InsertThread2(lpvoid   LpParamter)
{
    T_DbInsert   *   m_db   =   (T_DbInsert*)LpParamter;
    m_db-> f_fthread   =   TRUE;
    return   0;
}

void   main(void)
{
        bool   isend   =   false;
        thread1   =   CreteThread(NULL,0,InsertThread1,(lpvoid)&DbInsert1,0,NULL);
        thread1   =   CreteThread(NULL,0,InsertThread2,(lpvoid)&DbInsert2,0,NULL);
        while(!isend)
        {
              if((DbInsert1.f_fthread   ==   TRUE)   &&   (DbInsert2.f_fthread   ==   TRUE))
              {
                    isend   =   TRUE;
                    Afxmessagebox( "执行成功 ");
              }
        }
}

------解决方案--------------------
你要先保证你的两个线程都执行了各自的赋值操作后 再进入while 才能执行成功

------解决方案--------------------
static DWORD WINAPI InsertThread1(lpvoid LpParamter); 
有两个线程函数
这里怎么只声明了一个?
------解决方案--------------------
很明线,在release 版中,线程的执行速度没有main的执行速度快。专业地说是线程调度问题。

楼主既然已经在编写线程的程序了,想必对线程调度有了一定的了解。

你可以在main中这样:

C/C++ code

void   main(void)
{
        bool   isend   =   false;
        thread1   =   CreteThread(NULL,0,InsertThread1,(lpvoid)&DbInsert1,0,NULL);
        thread1   =   CreteThread(NULL,0,InsertThread2,(lpvoid)&DbInsert2,0,NULL);
        while(!isend)
        {
              if((DbInsert1.f_fthread   ==   TRUE)   &&   (DbInsert2.f_fthread   ==   TRUE))
              {
                    isend   =   TRUE;
                    Afxmessagebox( "执行成功 ");
              }
              Sleep(0); // 加这句的目的在于让程序有机会去执行去它线程。
        }
}

------解决方案--------------------
代码应该是没有问题
估计楼主是源代码更改弄出来的吧
.H里代码是MFC的,。CPP是C++的,声明的好像有点混乱

在DEBUG下调试,有些内存遗漏经常会发现不到,但如果在RELEASE下很容易就会暴露出来,VC比别的语言最让人头痛的就是内存遗漏,因为一旦发生这种情况找原因相比下有难度。