【发布时间】:2011-10-20 17:38:22
【问题描述】:
我有一个作业队列,我想创建一个由四个线程组成的池,我可以在其中投入我的作业。我坚持的是如何制作线程并在没有工作的情况下让它们暂停。
JOB QUEUE | job1 | job2 | job3 | job4 | ..
THREAD POOL | thread1 | thread2 | thread3 | thread4 |
在初始化点创建我当前拥有的线程:
for (t=0; t<num_of_threads; t++){
pthread_create(&(threads[t]), NULL, doSth2, NULL);
}
其中num_of_threads=4 和doSth2 是一个内部没有任何内容的函数。
因此,一旦我创建了 4 个线程并使用 doSth2 完成了它们,我怎样才能在不杀死它们的情况下给它们新的工作?
【问题讨论】:
标签: c pthreads threadpool reusability