#include <windows.h>
#include <iostream.h>DWORD WINAPI Fun1Proc(
  LPVOID lpParameter   // thread data
)
{
cout<<"thread1 is running"<<endl;
return 0;
}void main()
{
HANDLE hThread1; hThread1=CreateThread(NULL,0,Fun1Proc,NULL,0,NULL); CloseHandle(hThread1); cout<<"main thread is running"<<endl; Sleep(10);
}/*
为什么输出是
main thread is running
main thread is running
thread1 is running
 */

解决方案 »

  1.   

    主线程走太快,你又没有设置waitfor
      

  2.   

    主线程走太快,那么main thread is running怎么说也不能输出两行????
      

  3.   

    灵异事件?main thread is running 居然能输出2遍。。
      

  4.   

    肯定时,我是从VC6.0编辑器里面拷贝过来的
    (有时输出对,有是错)#include <windows.h>
    #include <iostream.h>DWORD WINAPI Fun1Proc(
      LPVOID lpParameter   // thread data
    )
    {
    cout<<"thread1 is running"<<endl;
    return 0;
    }void main()
    {
    HANDLE hThread1; hThread1=CreateThread(NULL,0,Fun1Proc,NULL,0,NULL); CloseHandle(hThread1); cout<<"main thread is running"<<endl; Sleep(10);
    }
      

  5.   

    前段时间回复了一个同样的问题,你在项目设置中把运行库改成多线程库就没问题了。参考这个帖子:
    http://topic.csdn.net/u/20090218/11/8FBEFB8E-F7AC-451F-8560-56ED04AD42A4.html
      

  6.   

    LS说的很好,在VC6中改成多线程运行库,VS2005中就没有LZ的问题了
      

  7.   

    多谢 cnzdgs 问题已解决!!!!