A multithreaded operating system simulation in Java implementing processor allocation, priority-based scheduling, and safe concurrency using locks and condition variables.
This project simulates core behavior of an operating system scheduler, including:
- Process registration with priorities
- Dynamic processor allocation
- Preemptive scheduling
- Blocking and signaling using
Conditionvariables - Thread-safe operations with
ReentrantLock
Itβs designed to emulate how an OS might manage limited CPU cores and prioritize tasks while ensuring thread safety and correctness.
- β Priority Queues (0β9) for handling processes by urgency
- β Multiple Processors Support (configurable dynamically)
- β
Fair Locking using
ReentrantLock(true) - β Condition Variables to block and wake threads efficiently
- β Graceful Handling of process termination and scheduling
OS-Simulation-Java/
βββ OS.java # Core operating system simulation
βββ OS_sim_interface.java# Interface definition (provided)
βββ Tests.java # Suite of unit & functional tests
βββ Main.java # Entry point to run tests
βββ README.md # You are here :)
-
Registering a Process:
Each process is assigned a unique PID and a priority from 0 (lowest) to 9 (highest). -
Starting a Process:
If a processor is free, it's immediately assigned. Otherwise, the process is enqueued based on its priority and blocks usingCondition.await(). -
Scheduling / Terminating:
Releases the processor, then signals the next-highest priority waiting process. -
Concurrency Management:
All shared state (queues, assignments) is guarded by a singleReentrantLock, ensuring correctness under multithreading.