我用api CreateThread();
可是在我的线程函数中 DWORD Thread1()
没有执行
不知道为什么
还请各位解答,如能付上一个小程序的代码,那就感激不尽了

解决方案 »

  1.   

    /*
     * Numbers.c
     *
     * sample code for "Multithreading Applications in Win32"
     * This is from Chapter 2,Listing 2_1
     *
     * Starts five threads and gives visible feedback
     * of these threads running by printing a number
     * passed in from the primary thread.
     *
    */#define WIN32_LEAN_AND_MEAN
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>DWORD WINAPI ThreadFunc(LPVOID);int main()
    {
       HANDLE hThrd;
       DWORD threadId;
       int i;   for (i=0;i<5;i++)
       {
          hThrd = CreateThread(NULL,
              0,
              ThreadFunc,
              (LPVOID)i,
              0,
              &threadId );
          if (hThrd)
          {
              printf("Thread launched %d\n",i);
          }
       }   // Wiat for the threads to complete.
       // We'll see a better way of doing this later.
       sleep(2000);   return EXIT_SUCCESS;
    }DWORD WINAPI ThreadFunc(LPVOID n)
    {
        int i;
        for (i=0;i<10;i++)
             printf("%d%d%d%d%d%d%d%d\n",n,n,n,n,n,n,n,n);
        return 0;
    }
      

  2.   

    int main()
    {
       HANDLE hThrd;
       DWORD threadId;
       hThrd = CreateThread(NULL,         0,
              (LPTHREAD_START_ROUTINE)ThreadFunc,
              (LPVOID)i,
              0,
              &threadId );
     if (hThrd)
          {
              printf("Thread launched %d\n",i);
          }
       }   // Wiat for the threads to complete.
    WaitForSingleObjeect(hThrd,INFINITE);   //等待线程结束。   return EXIT_SUCCESS;
    }DWORD WINAPI ThreadFunc(LPVOID n)
    {
        int i;
        for (i=0;i<10;i++)
             printf("%d%d%d%d%d%d%d%d\n",n,n,n,n,n,n,n,n);
        return 0;
    }