Skip to content

soddi1/mini-pthread

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

mini-pthread – Custom Threading Library in C

C Concurrency Synchronization Operating Systems

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.


Features

  • thread_create – Create new user-level threads
  • thread_exit – Terminate the calling thread
  • thread_join – Wait for a thread to finish
  • thread_sleep(ms) – Sleep a thread for a given duration
  • thread_yield() – Yield execution to other threads
  • context_switch() – Explicit context switching between threads

Synchronisation Support

  • Mutexes:
    • mutex_init(m)
    • mutex_acquire(m)
    • mutex_release(m)
  • Semaphores:
    • sem_init(sem, value)
    • sem_wait(sem)
    • sem_post(sem)

How It Works

  • Implements cooperative (non-preemptive) threading using setjmp / longjmp or ucontext for 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

About

A refined user-level threading library in C, mimicking the core functionalities of the POSIX pthread interface. Includes support for cooperative scheduling, context switching, mutexes, semaphores, and basic thread lifecycle management.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages