A multi-threaded traffic simulation system developed for an Operating Systems course. It models traffic flow through multiple intersections with support for emergency vehicles and intelligent traffic light controllers.
Specialized threads for:
- Traffic light control
- Vehicle generation
- Emergency vehicle handling
- Vehicle movement between roads
- Real-time GUI updates
- Configuration management
- System performance monitoring
- Hot-reloading of
config.txt - Adjustable parameters:
- Simulation duration
- Number of intersections and roads
- Vehicle generation rates
- Emergency vehicle limits
- Scheduling policies
- Visual representation of intersections
- Traffic light states: RED / GREEN / YELLOW
- Vehicle counts per road
- Emergency vehicle indicators
- System statistics dashboard
- Priority scheduling for emergency vehicles
- Special logic for critical situations
- Emergency vehicle statistics tracking
- Real-time CPU usage
- Memory consumption tracking
- Detailed traffic statistics
- Timestamped event logging
- Comprehensive simulation records
- Persistent log storage (
traffic_sim.log)
- POSIX
pthreadsfor concurrent execution - Mutexes for thread-safe operations
- Condition variables for synchronization
- Mutex locks for shared resource protection
- Condition variables for efficient waiting
- Atomic operations on shared data
inotifyfor dynamic config monitoring- Shared memory for intersection states
- Conditional signaling between threads
- Dynamic memory allocation
- File I/O for config and logging
- System-level resource tracking
- Priority-based scheduling for emergency vehicles
- Adaptive traffic light timing
- Load-based duration calculation
- Timed operations with
usleep - Periodic thread execution
- Real-time GUI/statistics updates
- Linux environment
- GCC compiler
- Ncurses library
- POSIX Threads (
pthreads) support
traffic_simulation/
├── src/
│ ├── config.c
│ ├── gui.c
│ ├── ipc.c
│ └── logger.c
│ ├── main.c
│ └── main.h
│ ├── monitoring.c
│ └── scheduler.c
├── config.txt
├── Makefile
└── README.md
├── traffic_sim.log (this will be created at the run time)# Clone the repo
git clone https://github.com/kinza7124/traffic_simulation.git
cd traffic_simulation
# Build the project
make clean
make
# Run the simulation
./traffic_simThis project is licensed under the MIT License. See LICENSE for more information.