CafeteriaPay is a Python-based Operating Systems simulation of a real-time university cafeteria payment system.
The project demonstrates how multiple POS counters and payment workers can safely process concurrent wallet transactions using multithreading, bounded queues, semaphores, mutex locks, per-wallet synchronization, and priority scheduling.
A Tkinter dashboard is included for monitoring wallet balances, queue activity, processing statistics, student creation, manual payment requests, and wallet funding.
During busy cafeteria hours, several payment counters may submit payment requests at the same time. The backend has limited queue capacity and only a few workers available to process those requests.
The system must ensure that:
- wallet balances are updated safely;
- two workers cannot modify the same wallet simultaneously;
- pending requests do not exceed the queue capacity;
- producers wait when the queue is full;
- consumers wait when the queue is empty;
- rush requests receive priority without completely starving normal requests;
- successful and failed transactions are logged;
- queue and payment statistics remain visible while the simulation runs.
CafeteriaPay models this scenario as a classic producer-consumer concurrency problem.
| Concept | Implementation |
|---|---|
| Multithreading | POS counters, workers, monitor and GUI operate through separate threads |
| Producer-Consumer Model | Producers generate requests and consumers process them |
| Bounded Buffer | Pending requests are stored in a fixed-capacity queue |
| Semaphores | Empty and filled queue slots control producer/consumer blocking |
| Mutex Lock | Protects shared queue operations |
| Per-Account Lock | Prevents race conditions during wallet balance updates |
| Priority Scheduling | Rush payments are processed before normal requests |
| Fairness | Scheduler attempts a 2 Rush → 1 Normal processing pattern |
| Critical Section | Balance checking and deduction occur while holding a wallet lock |
| Logging | Transactions and processing results are recorded |
| Real-Time Monitoring | Dashboard displays queues, counters and balances |
- Multiple synchronized student wallet accounts
- Rush and normal payment-request queues
- Fixed-capacity bounded queue
- Two concurrent payment worker threads
- Safe wallet balance deductions
- Insufficient-balance detection
- Priority-based request processing
- Real-time queue statistics
- Produced, consumed, successful and failed payment counters
- Transaction logging to console and file
- Student creation through the dashboard
- Manual payment request submission
- Wallet funding option
- Tkinter-based live monitoring dashboard
POS Counter / Manual Request
↓
Bounded Queue
┌──────────────┐
│ Rush Requests│
│Normal Requests
└──────────────┘
↓
Priority Scheduler
↓
Worker Threads
↓
Account Manager
↓
Logger + Monitor
↓
Tkinter Dashboard
- A payment request is created with:
- request ID
- student ID
- payment amount
- priority
- timestamp
- The request is inserted into the bounded queue.
- A worker waits for an available request.
- The scheduler selects a rush or normal request.
- The worker acquires the selected wallet's lock.
- The system checks whether the wallet has enough balance.
- The amount is safely deducted or the request is marked as failed.
- The result is written to the console and execution log.
- The dashboard updates queue sizes, statistics and balances.
CafeteriaPay-Concurrent-Payment-System/
│
├── src/
│ ├── main.py
│ ├── account_manager.py
│ ├── queue_manager.py
│ ├── producer.py
│ ├── consumer.py
│ ├── scheduler.py
│ ├── logger.py
│ ├── monitor.py
│ └── monitor_gui.py
│
├── screenshots/
│ ├── 01-dashboard-overview.png
│ └── 02-priority-scheduling-console.png
│
├── logs/
│ └── sample_execution_log.txt
│
├── requirements.txt
├── .gitignore
└── README.md
The dashboard displays:
- rush and normal queue sizes;
- produced, consumed, successful and failed payment counts;
- student wallet balances;
- student creation controls;
- manual payment requests;
- wallet funding controls.
The console demonstrates multiple worker threads processing rush and normal requests and logging successful transactions.
| Category | Technology |
|---|---|
| Programming Language | Python |
| GUI | Tkinter |
| Concurrency | threading |
| Synchronization | Locks, mutexes and semaphores |
| Scheduling | Custom priority scheduler |
| Logging | Console and text-file logging |
| Interface | Desktop dashboard + console output |
Python 3.10 or newer is recommended.
Check your installation:
python --versionOn some systems:
python3 --versiongit clone https://github.com/fayzliaqat/CafeteriaPay-Concurrent-Payment-System.git
cd CafeteriaPay-Concurrent-Payment-SystemFrom the repository root:
python src/main.pyOn some systems:
python3 src/main.pyThe console simulation will start and the Tkinter dashboard will open.
No third-party Python package is required.
The project uses modules available in the Python standard library, including:
threading
tkinter
time
random
uuid
datetime
pathlib
On some Linux distributions, Tkinter may need to be installed separately:
sudo apt install python3-tkCreates a wallet account using the entered name and initial balance.
Allows the user to:
- select a student;
- enter a payment amount;
- choose
RushorNormalpriority; - add the request to the processing queue.
Adds funds to the selected student's wallet.
Clears the currently displayed rush and normal queues.
Starting CafeteriaPay Simulation
AUTO CREATED: SID-001($100) | SID-002($150) | SID-003($200)
Priority test queue ready
Worker-0 → Rush REQ | SID3
Worker-1 → Rush REQ | SID1
Worker-0 → Normal REQ | SID2
Worker-1 → Normal REQ | SID1
Worker-0 processed rush1 | Student: 3 | Amount: $25 | Priority: Rush | Status: SUCCESS
Worker-1 processed rush2 | Student: 1 | Amount: $10 | Priority: Rush | Status: SUCCESS
Worker-0 processed norm1 | Student: 2 | Amount: $15 | Priority: Normal | Status: SUCCESS
Worker-1 processed norm2 | Student: 1 | Amount: $20 | Priority: Normal | Status: SUCCESS
Creates and manages wallet accounts and performs synchronized balance updates.
Stores rush and normal requests and controls bounded-buffer access using synchronization primitives.
Generates payment requests and submits them to the queue.
Represents payment workers that retrieve and process pending requests.
Implements rush/normal priority selection and fairness logic.
Records request production, consumption and payment results.
Displays queue and transaction statistics.
Provides the live Tkinter dashboard and manual controls.
Initializes accounts, queues, workers, monitoring and the dashboard.
The queue is shared between request producers and worker consumers.
It is protected using:
- an empty-slot semaphore;
- a filled-slot semaphore;
- a mutex for rush and normal queue modifications.
Each wallet contains its own lock.
This allows different wallets to be updated concurrently while ensuring that only one worker can check and modify the same wallet balance at a time.
Rush requests receive higher priority. The scheduler uses a fairness rule intended to process:
2 Rush requests → 1 Normal request
when both types are available.
- Student wallet accounts
- Payment request objects
- Producer and consumer architecture
- Bounded payment queue
- Concurrent worker threads
- Rush and normal priority levels
- Fair scheduling policy
- Safe wallet deductions
- Successful and failed payment logging
- Real-time queue and processing statistics
- Execution log
- GUI-based monitoring
- The project is a simulation rather than a production payment platform.
- Data is stored in memory and resets after the application closes.
- There is no database or user authentication.
- Payment requests are generated locally.
- The dashboard is designed for desktop execution.
- Queue-clearing and shutdown behavior can be improved further.
- Add graceful thread shutdown
- Add persistent wallet and transaction storage
- Add detailed transaction-history tables
- Add configurable queue capacity
- Add configurable producer and worker counts
- Add automated tests for concurrency behavior
- Add charts for payment throughput and failure rates
- Export transaction history to CSV
- Add role-based login for administrators
- Improve queue reset behavior
python
operating-systems
multithreading
concurrency
producer-consumer
semaphore
mutex
thread-synchronization
priority-scheduling
tkinter
bounded-buffer
academic-project
Fayz Liaqat
Artificial Intelligence Student

