User-Level Context Switching & Systems Programming in C
user-context-switching is a C-based project that explores low-level systems programming concepts, including multi-threading with pthreads, bit manipulation, and user-level context switching using the ucontext.h library.
The project is divided into three parts:
-
Implementing thread synchronization using pthreads.
-
Writing utilities for bit-level operations.
-
Debugging and fixing a non-terminating ucontext-based context switching program.
This work demonstrates foundational OS concepts like concurrency, memory representation, and cooperative multitasking.
-
🧵 Multi-threading with pthreads: Created multiple threads that safely update a shared variable with mutex locks to prevent race conditions.
-
⚡ Bit manipulation utilities: Implemented functions to extract top bits, set a bit at a given index, and get a bit at a given index in a bitmap.
-
User-level context switching: Used getcontext, makecontext, and setcontext to implement cooperative multitasking with separate stacks.
-
Bug fix for non-termination: Introduced a guard variable to ensure the program runs the worker once, returns to main, frees resources, and exits cleanly.
-
🖥️ Demonstrates OS fundamentals: Hands-on practice with execution contexts, stack management, and concurrency primitives.
-
Programming Languages/Technologies: C, POSIX pthreads, ucontext.h
-
Concurrency Tools: pthreads (threads, mutexes), user-level context switching.
-
Development Tools: GCC/Clang, Makefile, VS Code, Git, GitHub
-
Extend bit manipulation functions to support more advanced bitmap operations.
-
Implement a simple user-level scheduler for multiple workers using swapcontext.
- Kelvin Ihezue, Bryan Shangguan