- Project Overview
- Research and Foundations
- The Basic Library
- Synchronization: Mutexes
- Scheduling Algorithms
A user-level thread library made to understand POSIX threads. The best way to learn something is the make it!
- Read Documentation: Understand the project requirements.
- Master
ucontext: Focus onswapcontextfor switching between execution flows.
- Scheduler Context: Needed for handling context swaps.
- Main Thread Context: Needed for benchmarks and returning to the entry point.
- TCB (Thread Control Block): Defined in
thread_worker_type.h. - Context: Each TCB holds a
ucontext. - RunQueue: A list of TCBs that are ready to run.
worker_create(): Mallocs the stack (SIGSTKSZ) and usesmakecontext().worker_yield(): Voluntarily pauses the current thread.worker_exit(): Saves return value and cleans up the TCB.worker_join(): Blocks the current thread until the target thread exits.
worker_mutex_init(): Initialize the lock.worker_mutex_lock(): Locks the mutex or blocks the thread if held.worker_mutex_unlock(): Unlocks and wakes up waiting threads.worker_mutex_destroy(): Cleanup; ensure lock is free before destroying.
- Baseline implementation.
- No preemption.
- FCFS with preemption.
- Quantum: Fixed time limit per thread.
- Implementation: Use
sigaction()and timers to trigger the scheduler handler.