A high-level thread management library for C that abstracts the complexity of working with pthreads. It allows easy creation, assignment, and management of worker threads.
Hey, I'm Afonso, a passionate developer who loves low-level C/C++ and even some assembly!
I originally created this library as a proof-of-concept, but it quickly evolved into something much bigger.
If you're interested in learning how it works, check out the GUIDE.md and the main.c file, along with all the headers in the include/ directory.
Of course! Feel free to create a new issue if you ever find any when using the library.
- Thread Pool Management – Efficiently manages a pool of worker threads.
- Dynamic Task Assignment – Assign tasks to available threads dynamically.
- Thread Safety – Built-in mutex handling for safe multithreading.
- Lightweight & Fast – Optimized for minimal overhead.
- Cross-Platform Compatibility – Works on Linux and Windows (via pthreads).
- C Compiler (GCC, Clang, MSVC)
- CMake (optional, for easier builds)
- pthreads (POSIX thread library)
Clone the repository:
git clone https://github.com/AfonsoCMSousa/Thread-Master.git
cd Thread-MasterOr compiple manually:
gcc -o my_program src/main.c include/threadlib/threadlib.c -pthreadCheck the releases for a detailed instalation guide and some libraries (.a) (.dll) or even (.lib).
void thread_master_init(int max_threads, void *(*__thread_worker__)(void *), void *custom_params);Initializes the thread master with a specified number of threads and a worker function.
max_threads: The maximum number of threads to be used.__thread_worker__: The function pointer to the worker function that each thread will execute.custom_params: Custom parameters to be passed to the worker function.
void thread_mutex_init(pthread_mutex_t *mutex);Initializes a mutex.
mutex: Pointer to the mutex to be initialized.
void thread_mutex_destroy(pthread_mutex_t *mutex);Destroys a mutex.
mutex: Pointer to the mutex to be destroyed.
void thread_master_free();Frees resources allocated by the thread master.
void thread_master_get_status();Retrieves the status of the thread master.
void thread_master_assign_new_job(void *(*__thread_worker__)(void *), void *custom_params);Assigns a new job to the thread workers.
__thread_worker__: The function pointer to the worker function that each thread will execute.custom_params: Custom parameters to be passed to the worker function.
src/main.c: Contains the main function and the thread worker example of use.include/threadlib/threadlib.h: Header file for the thread library.include/threadlib/threadlib.c: Implementation of the thread library.
- Professor Marco Ferreira
- Professor Patrício Domingues
This content falls under Apache License Version 2.0
Have questions or suggestions? Feel free to reach out!
- 📧 Email: afonsoclerigomendessousa@gmail.com
- 🐙 GitHub: AfonsoCMSousa