Reputation: 2291
does the pthread lib include a threadpool implementation? or are there commonly used libs that folks use/
Upvotes: 4
Views: 2601
Reputation: 106
Jeanna Matthews from Clarkson University has a very nice implementation. Why don't you take a look? It follows the standard thread pool pattern.
Upvotes: 4
Reputation: 3057
In POSIX stander thraed are created with pthread_create function:
int pthread_create(pthread_t *thread_id,
const pthread_attr_t * attr,
void *(*start_routine)(void*), void *arg);
for implementing thread pool, i will suggest you to create a bunch of threads with pthread_create
function, and once the threads are created then use counting semaphore
. To manage the thread allocation.
Upvotes: 1
Reputation: 12866
Thread pools require some form of inter-thread communication to dispatch tasks which is beyond the remit of basic threading functionality.
Consider something like ØMQ which provides messaging functionality with ITC, IPC, TCP, and PGM sockets all using the same single BSD socket compatible API. One of the ØMQ socket types implements thread pool type functionality but can be extended over multiple hosts and hence is provides significantly greater scalability and flexibility.
Upvotes: 3
Reputation: 37930
There is no official pthread threadpool library, though there are plenty of other people's libraries to be found via Google.
Upvotes: 2