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!
- Dynamic job generation and arrival.
- Concurrent execution using mutex and semaphore synchronization.
- Color-coded log output for easy monitoring.
- Performance statistics displayed after execution.
- 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.
- Comprehensive Sanitizer Integration:
- Address Sanitizer for memory errors.
- Undefined Behavior and Leak Sanitizers.
- Robust Warning Flags:
- Includes
-Wall
,-Wextra
,-Werror
, and-Wformat-security
.
- Includes
- Testing Infrastructure:
- Unit tests for all components.
- Memory leak detection.
- Thread safety validation and stress testing.
- Performance benchmarking.
sudo apt update
sudo apt install build-essential libcunit1-dev
sudo apt install docker.io
-
Clone the repository:
git clone https://github.com/AliQ-AFK/multithreaded_job_scheduler.git cd multithreaded_job_scheduler
-
Build the project:
make all
make run
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 |
- β
Linux (Primary platform):
- Ubuntu (recommended).
- Debian.
- Other Linux distributions.
β οΈ macOS (Not tested, may require modifications).- β Windows (Not supported natively).
- Recommended: Use WSL (Windows Subsystem for Linux):
wsl --install wsl --install -d Ubuntu
- Alternative: Use a Linux virtual machine.
make all
Includes:
- All sanitizers.
- Debug symbols.
- Maximum warning levels.
- Thread safety checks.
make prod
Includes:
- Optimization flags (
-O2
). - Minimal runtime overhead.
- Production-ready performance.
.
βββ 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
# Clean build files
make clean
# Clean log files
make clean-logs
# Clean everything
make clean-all
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.
Three synchronization mechanisms are implemented:
-
Mutex-based Execution:
- Traditional mutual exclusion.
- Strict resource access control.
- Deadlock prevention.
-
Semaphore-based Execution:
- Resource counting mechanism.
- Multiple access control.
- Fair scheduling.
-
Unsynchronized Execution:
- No synchronization mechanisms.
- Used for performance comparison.
- Demonstrates race conditions.
Each execution method provides:
- Total jobs processed.
- Print/scan job completion rates.
- Execution time statistics.
- Thread-specific performance data.
- Resource utilization metrics.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature
). - Commit your changes (
git commit -m 'Add some AmazingFeature'
). - Push to the branch (
git push origin feature/AmazingFeature
). - Open a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
-
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.