Windows线程的CloseHandle

时间:2013-04-07 17:22:51

标签: c++ multithreading winapi threadpool

这是一个基本问题。我正在研究win32线程和C ++。 Closehandle如何在下面的代码中工作?在每次迭代中,是否创建了5个线程?或者只为整个程序创建了5个线程并在每次迭代中重新使用?如果没有,如何调用threadpool?这里的任务只是从每个线程的队列中获取一个元素,并对这些元素进行操作。

thread_fun(..) {
//synchronize to get one element for each thread
}
main() {
    for(int i=0; i<100; i++) {
    //Fill queue with 10000 elements and pass this to thread function
         for(int j=0;j<5;j++)
             _beginthreadex(..);
         WaitForMultipleObjects(..);
     }
    for(int j=0;j<5;j++)
         CloseHandle(..);
}

请赐教。

0 个答案:

没有答案