User-Threads
Implementation of a user-level multithreading library supporting multiple mapping models in C.
🛠️ Tech Stack
- Languages: C
- Concepts: Systems Programming, Multithreading, Coroutines, Synchronization, Signal Handling
- Tools & System Calls : Bash, setjmp/longjmp, CLONE
📌 Description
- threadHive is a user-level multithreading library that provides APIs for thread creation, joining, blocking, destruction, and signal handling in threads.
- Supports three multithreading models:
- One-One Model: Maps one user thread to one kernel thread using
clone(); threads are managed in a linked list with metadata like thread ID and function pointer. - Many-One Model: Maps multiple user threads to a single kernel thread; context saved using jump buffers, scheduling handled via SIGALRM with FCFS strategy.
- Many-Many Model: Multiplexes many user threads to multiple kernel threads; each kernel thread has its own scheduler, with separate linked lists for user and kernel threads.
- One-One Model: Maps one user thread to one kernel thread using
- Provides APIs for thread management:
-
thread_create(),thread_join(),thread_exit(),thread_kill() -
thread_lock()andthread_unlock()for spinlock-based synchronization
-
- Implemented round-robin scheduler for many-one and many-many models, using
setjmp/longjmpfor context switching. - Built linked list data structures to manage threads and their associated metadata (thread descriptor, function descriptor).
- Validated the library with test programs like race condition scenarios and matrix multiplication, achieving significant improvements in efficiency and control over thread execution.