1
3
Fork
You've already forked c_threadpool
0
A tiny C99 pthread threadpool implementation.
  • C 97.2%
  • Makefile 2.8%
2025年03月18日 09:09:57 +00:00
.gitignore update gitignore 2025年03月18日 10:09:29 +01:00
LICENSE Add LICENSE 2025年03月17日 19:06:52 +00:00
Makefile CC variable in makefile 2025年03月18日 10:08:49 +01:00
README.md Update README.md 2025年03月17日 20:50:30 +00:00
test.c add license header to files 2025年03月17日 21:49:08 +01:00
threadpool.c add license header to files 2025年03月17日 21:49:08 +01:00
threadpool.h add license header to files 2025年03月17日 21:49:08 +01:00

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;
}