Skip to content

AliQ-AFK/multithreaded_job_scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

78 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Multithreaded Job Scheduler

Build Status License Platform

A highly efficient, multithreaded job processing system stimulation demonstrating the power of concurrency using multiple synchronization mechanisms, including mutexes and semaphores.

πŸ’‘ If you like this project, please ⭐ star the repository to show your support!


πŸ“Ί Demo

Job Processing Demo

Steps Shown in the Demo:

  1. Dynamic job generation and arrival.
  2. Concurrent execution using mutex and semaphore synchronization.
  3. Color-coded log output for easy monitoring.
  4. Performance statistics displayed after execution.

πŸš€ Features

Core Functionality

  • Multiple Synchronization Methods:
    • Mutex-based execution for strict mutual exclusion.
    • Semaphore-based execution for resource counting.
    • Unsynchronized execution for performance comparison.
  • Job Processing:
    • Print and scan job simulation.
    • Dynamic job generation and arrival time-based scheduling.
    • Page-based job execution.

Development Features

  • Comprehensive Sanitizer Integration:
    • Address Sanitizer for memory errors.
    • Undefined Behavior and Leak Sanitizers.
  • Robust Warning Flags:
    • Includes -Wall, -Wextra, -Werror, and -Wformat-security.
  • Testing Infrastructure:
    • Unit tests for all components.
    • Memory leak detection.
    • Thread safety validation and stress testing.
    • Performance benchmarking.

πŸ“₯ Installation

Prerequisites

Required Packages (Ubuntu/Debian):

sudo apt update
sudo apt install build-essential libcunit1-dev

Optional (Docker):

sudo apt install docker.io

Installation Steps

  1. Clone the repository:

    git clone https://github.com/AliQ-AFK/multithreaded_job_scheduler.git
    cd multithreaded_job_scheduler
  2. Build the project:

    make all

🚦 Usage

Run the Program

make run

Testing Commands

Command Description
make test-jobs Run job generation tests
make test-execution Test execution correctness with all methods
make test-scheduler Validate scheduler behavior
make test-memory Run memory sanitizers for leaks and errors
make test-threads Test thread safety and concurrency
make test-threads-stress Perform 100 iterations of thread stress testing
make test-threads-valgrind Test with Valgrind for detailed thread errors

⚠️ Platform Compatibility

Supported Platforms:

  • βœ… Linux (Primary platform):
    • Ubuntu (recommended).
    • Debian.
    • Other Linux distributions.
  • ⚠️ macOS (Not tested, may require modifications).
  • ❌ Windows (Not supported natively).

Windows Users:

  1. Recommended: Use WSL (Windows Subsystem for Linux):
    wsl --install
    wsl --install -d Ubuntu
  2. Alternative: Use a Linux virtual machine.

πŸ› οΈ Build Configurations

Development Build (Default)

make all

Includes:

  • All sanitizers.
  • Debug symbols.
  • Maximum warning levels.
  • Thread safety checks.

Production Build

make prod

Includes:

  • Optimization flags (-O2).
  • Minimal runtime overhead.
  • Production-ready performance.

πŸ“Š Project Structure

.
β”œβ”€β”€ src/                    # Source files
β”‚   β”œβ”€β”€ execution.c         # Core execution logic
β”‚   β”œβ”€β”€ job_generation.c    # Job creation and management
β”‚   β”œβ”€β”€ mutex_execution.c   # Mutex-based synchronization
β”‚   β”œβ”€β”€ semaphore_execution.c # Semaphore-based synchronization
β”‚   └── unsync_execution.c  # Unsynchronized execution
β”œβ”€β”€ include/               # Header files
β”‚   β”œβ”€β”€ execution.h        # Execution definitions
β”‚   β”œβ”€β”€ job.h              # Job structure definitions
β”‚   └── utils.h            # Utility functions
β”œβ”€β”€ test/                  # Test suite
β”‚   β”œβ”€β”€ test_execution.c
β”‚   β”œβ”€β”€ test_job_generation.c
β”‚   └── test_schedule.c
β”œβ”€β”€ log/                   # Log directory
└── makefile               # Build system

🧹 Cleanup

# Clean build files
make clean

# Clean log files
make clean-logs

# Clean everything
make clean-all

πŸ” Logging System

The project includes a comprehensive logging system with:

  • Dedicated log directory for all execution types.
  • Color-coded log levels for better readability.
  • Thread-specific logging for debugging.
  • Automatic cleanup functionality.
  • Detailed execution tracking and timing.

πŸ”’ Thread Safety

Three synchronization mechanisms are implemented:

  1. Mutex-based Execution:

    • Traditional mutual exclusion.
    • Strict resource access control.
    • Deadlock prevention.
  2. Semaphore-based Execution:

    • Resource counting mechanism.
    • Multiple access control.
    • Fair scheduling.
  3. Unsynchronized Execution:

    • No synchronization mechanisms.
    • Used for performance comparison.
    • Demonstrates race conditions.

πŸ“Š Performance Monitoring

Each execution method provides:

  • Total jobs processed.
  • Print/scan job completion rates.
  • Execution time statistics.
  • Thread-specific performance data.
  • Resource utilization metrics.

🀝 Contributing

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


🎯 Future Improvements

Planned Features:

  • Cross-platform Support: Extend compatibility to Windows and macOS natively.

  • Dynamic Thread Pooling: Implement a thread pool to optimize resource utilization for job processing.

  • Json Logs: Convert the Logs into a Json format.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published