mini-pthread is a lightweight implementation of a threading library that replicates the core behaviour of POSIX pthreads at the user level, built from scratch in C. It supports cooperative multitasking, thread lifecycle control, manual context switching, and basic synchronization primitives.
thread_create– Create new user-level threadsthread_exit– Terminate the calling threadthread_join– Wait for a thread to finishthread_sleep(ms)– Sleep a thread for a given durationthread_yield()– Yield execution to other threadscontext_switch()– Explicit context switching between threads
- Mutexes:
mutex_init(m)mutex_acquire(m)mutex_release(m)
- Semaphores:
sem_init(sem, value)sem_wait(sem)sem_post(sem)
- Implements cooperative (non-preemptive) threading using
setjmp/longjmporucontextfor context switching - Threads are managed in a queue with a simple scheduler
- Each thread has its own stack and context
- Mutexes and semaphores block/yield threads without kernel involvement