A tiny C99 pthread threadpool implementation.
- C 97.2%
- Makefile 2.8%
| .gitignore | update gitignore | |
| LICENSE | Add LICENSE | |
| Makefile | CC variable in makefile | |
| README.md | Update README.md | |
| test.c | add license header to files | |
| threadpool.c | add license header to files | |
| threadpool.h | add license header to files | |
A simple and hackable threadpool implementation written in C99 for the UNIX pthreads API.
To use, simply copy threadpool.c and threadpool.h into your project.
The API is as straightforward as the installation process.
#include "threadpool.h"#include <stdio.h>#include <unistd.h>
void make_flapjacks() {
for (int i = 0; i < 10; i++) {
printf("Flapjacks!\n");
sleep(1);
}
}
void make_applepie() {
for (int i = 0; i < 10; i++) {
printf("Apple Pie!\n");
sleep(1);
}
}
void make_cookies() {
for (int i = 0; i < 10; i++) {
printf("Cookies!\n");
sleep(1);
}
}
int main(int argc, char **argv) {
threadpool threadp = threadpool_init(24);
threadpool_start(&threadp);
threadpool_execute(&threadp, make_cookies);
threadpool_execute(&threadp, make_applepie);
threadpool_execute(&threadp, make_flapjacks);
threadpool_execute(&threadp, make_cookies);
getchar(); // Wait
threadpool_done(&threadp);
return 0;
}