我觉得他不会影响,因为实例都是新 new 出来的,自然不一样,而指针在线程
各自的堆栈里,也不会影响。线程的建立和释放是操作系统来做的。
windows 核心编程推荐使用 _beginthreadex 和 endthread 来建立和终止线
程,c 运行库可以为线程做一些辅助工作。

解决方案 »

  1.   

    如果classX1之中包含静态成员变量或者静态成员函数,要考虑变量访问冲突或者函数重入的问题。线程正常结束(return afxendthread 等等) deallocates the thread’s stack, detaches all DLLs attached to the thread, and deletes the thread object from memory
    线程被终止(TerminateThread)the target thread has no chance to execute any user-mode code and its initial stack is not deallocated. DLLs attached to the thread are not notified that the thread is terminating. 
      

  2.   

    to  pitchstar(一站) :
    c 运行库可以为线程做一些辅助工作-- 是什么意思,可以做那些工作?
    c/c++本身可以做多线程的东西吗(,不用WINDOWS的类库)。另外我用_beginthreadex的时候,编译无法通过。我看里面定义了一个_MT的宏。
      

  3.   

    在project settings里面改设置就可以了,手动改编译名领行参数太麻烦。
      

  4.   

    classX1之中不包含静态成员变量或者静态成员函数,否则后果不可预测,
    如果他们不存在同步问题,这就好办了,但当用你的资源时你得注意资源线程终止时,在内部终止时用AfxEndThread
               当外部终止时尽量不用Terminatethread方法,用       PostThreadMessage 的WM_QUIT消息较好,但你必须确定你的线程终止了
      

  5.   

    谢谢各位。
    先明确一下,我的程序里面没有静态的东西。
    另外我想知道,怎么样传几个参数到线程的函数里去。可以直接用那个lpvoid参数吗,如果是,请问怎么用?
      

  6.   

    好,差不多了,刚刚看了windows核心编程,也理解了。该给分了。
    谢谢各位。