# developerx-coder/cpu_simulation architecture

> Architecture diagram of the GitHub repository developerx-coder/cpu_simulation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/developerx-coder/cpu_simulation
- Repository: https://github.com/developerx-coder/cpu_simulation

## Overview

##### Project Overview
- This is a C++ simulation project that mimics a multithreaded CPU process scheduling system with integrated RAM management and resource allocation using semaphores.
- Its purpose is to simulate realistic operating system behavior (process scheduling, resource sharing, deadlock prevention) which makes it useful for research and testing in OS scheduling, real-time computing, and parallel processing.

##### Main Components
a. CPU Component:
- Found in CPU/CPU.h.
- Represents the simulation of CPU cores using multithreading (with std::thread) and implements the Round Robin scheduling algorithm.

b. RAM Management Component:
- Found in RAM/RAM.h.
- Implements a priority queue (min-heap based) to store and retrieve processes.
- Scheduling order based on priority.

c. Resource Manager:
- Found in RESOURCES/RESOURCE_MANAGER.h.
- Manages the allocation of shared resources using semaphores (implemented with std::mutex).
- To include the mechanism for deadlock prevention via safe wait-and-signal operations.

d. Entry Point:
- main.cpp serves as the program's entry point, initializing the components and triggering simulation execution.

##### Relationships and Interactions
- The CPU core(s) interact with RAM to fetch processes based on priority.
- CPU cores then request shared resources via the Resource Manager.
- Processes, once executed and completed, release resources back to the Resource Manager.
- Multi-threading by possibly annotating the CPU component as having “multiple threads” (each representing a simulated CPU core executing processes concurrently).

##### Architectural Patterns and Principles
- The project leverages a layered, modular design where each major component (CPU, RAM, Resource Manager) is separated by clear interfaces.
- The use of Round Robin scheduling and priority-based fetching from RAM indicates an emphasis on fair, time-sliced, and priority-aware processing.

##### Technologies and Libraries
- C++ (with modern C++ features such as multithreading).
- Standard Library components: std::thread, std::mutex, std::queue (priority queue).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["main.cpp: Entry Point (Initializes Simulation)"]:::entry
    B["CPU (Multi-threaded Core Management with Round Robin)"]:::cpu
    C["RAM (Priority Queue based Memory Management)"]:::ram
    D["Resource Manager (Semaphore-based Resource Allocation)"]:::resources

    A -->|"initiates"| B
    A -->|"initiates"| C
    A -->|"initiates"| D

    C -->|"fetches process (priority)"| B
    B -->|"requests resource"| D
    B -->|"releases resource"| D
    B ---|"multithreading (std::thread)"| B

    click A "https://github.com/developerx-coder/cpu_simulation/blob/main/main.cpp"
    click B "https://github.com/developerx-coder/cpu_simulation/blob/main/CPU/CPU.h"
    click C "https://github.com/developerx-coder/cpu_simulation/blob/main/RAM/RAM.h"
    click D "https://github.com/developerx-coder/cpu_simulation/blob/main/RESOURCES/RESOURCE_MANAGER.h"

    classDef entry fill:#87CEFA,stroke:#333,stroke-width:2px;
    classDef cpu fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef ram fill:#ADFF2F,stroke:#333,stroke-width:2px;
    classDef resources fill:#FF6347,stroke:#333,stroke-width:2px;
```
