Skip to content

Kelony11/User-Context-Switching

Repository files navigation

user-context-switching

User-Level Context Switching & Systems Programming in C

PROJECT OVERVIEW

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:

  1. Implementing thread synchronization using pthreads.

  2. Writing utilities for bit-level operations.

  3. Debugging and fixing a non-terminating ucontext-based context switching program.

This work demonstrates foundational OS concepts like concurrency, memory representation, and cooperative multitasking.

KEY FEATURES 🔑

  • 🧵 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.

TECHNICAL STACK 🧱

  • 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

WHAT'S NEXT?

  • Extend bit manipulation functions to support more advanced bitmap operations.

  • Implement a simple user-level scheduler for multiple workers using swapcontext.

Contributors

  • Kelvin Ihezue, Bryan Shangguan

About

A C systems programming project showcasing multi-threading, bit manipulation, and user-level context switching with ucontext.h.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors