我想达到这样效果:
1,一共要建立1000个线程。
2,运行线程数在100个上下。
3,直到线程全部执行。
该怎么设计这个呢?
、、
我还有个问题就是 ,在createthread后,让线程立即运行(创建线程-执行线程-创建-执行),该怎么做?

解决方案 »

  1.   


    创建这么多线程都需要相当长时间了AfxBeginThread创建线程的时候可以指定是否立即运行,看看MSDN上这个函数的参数吧
      

  2.   

    createthread后 线程就会立即执行等待线程执行完毕用 WaitForSingleObject这两项都可以用个for循环
      

  3.   

    AfxBeginThread创建线程需要一定的消耗的,最好重新规划下。
      

  4.   

    1.AfxBeginThread( AFX_THREADPROC pfnThreadProc, LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );
    dwCreateFlagsSpecifies an additional flag that controls the creation of the thread. This flag can contain one of two values: CREATE_SUSPENDED   Start the thread with a suspend count of one. The thread will not execute until ResumeThread is called.
    0   Start the thread immediately after creation. (立即执行)2.WaitForSingleObject, WaitForMultipleObjects
      

  5.   

    to;dirdirdir3
      我这个肯定要搞并行处理的。
    to:Seu_why 
      我试试
      

  6.   

    用一个控制线程来创建和管理其它所有进程..在控制线程里用一个循环对每个线程调用waitforsingleobject(handle[i],0)..当返回值为WAIT_OBJECT_0时,计数加一,当加到总开启的线程数时,退出循环,提示所有线程完成.