Skip to content

mistgc/thrpl.c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

thrpl.c

An implementation of Thread Pool in C.

Run an example

The thread pool uses POSIX threads, so compile using the -lpthread flag.

gcc example.c thrpl.c -lpthread -o example && ./example

Debug mode:

gcc example.c thrpl.c -lpthread -DTHRPL_DEBUG -o example && ./example

Usage

git clone https://github.com/zaiic/thrpl.c
cd thrpl.c

Put thrpl.c and thrpl.h in your project or generate a header-only file and put it in your project.

Generate header-only file:

./generate_header_only.sh

Notice: The header-only file is stb style. Don't forget to put #define THRPL_IMLEMENTATION in your file before including header-only file.

#define THRPL_IMLEMENTATION

#include "thrpl.h" // header-only file

Api

Function Description
ThreadPool *ThreadPool_new() Create a new thread pool and return a pointer to it.
int ThreadPool_add_task(ThreadPool *self, Task task) Add a task to the thread pool.
int ThreadPool_gracefully_destroy(ThreadPool *self) Destroy the thread pool when the task queue is empty.
int ThreadPool_destroy(ThreadPool *self) Destroy the thread pool.
typedef void *(*function)(void *);

typedef struct {
  function func;
  void *argv;
} Task;

License

The MIT License

About

An implementation of Thread Pool in C.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published