A robust seat reservation system built in C intended for Linux environments. This project demonstrates high-concurrency handling using System V IPC primitives (Shared Memory and Semaphores) combined with a Multi-threaded Server Architecture.
It solves the classic "Booking Race Condition" problem without using TCP/IP sockets, relying instead on direct kernel-level memory sharing for ultra-low latency communication between processes.
The system operates on a Hybrid Process/Thread model:
- Main Server Process: Manages the global seat map in Shared Memory.
- Worker Threads: Spawns a detached
pthreadfor each incoming client connection. - Private Channels: Dynamically allocates a unique Shared Memory segment and Semaphore set for private communication between a specific Client process and its assigned Server Thread.
sequenceDiagram
participant Client
participant ServerMain
participant ServerThread
participant SharedSeatMap
Client->>ServerMain: Request Connection (Sem Wait)
ServerMain->>Client: Send Comm Keys (Shared Mem)
ServerMain->>ServerThread: Spawn Worker Thread
loop Session
Client->>ServerThread: Select Seat X (Private SHM)
ServerThread->>SharedSeatMap: Check Availability (Sem Lock)
alt is Available
SharedSeatMap-->>ServerThread: Lock Success
ServerThread-->>Client: "Available"
Client->>ServerThread: "Buy"
ServerThread->>SharedSeatMap: Mark Occupied
else is Occupied
SharedSeatMap-->>ServerThread: Lock Fail
ServerThread-->>Client: "Occupied"
end
ServerThread->>SharedSeatMap: Release Lock
end
-
IPC Wrapper Library (
ipc_utils): A custom abstraction layer over<sys/shm.h>and<sys/sem.h>to simplify memory segment allocation and semaphore operations (PandVoperations implemented asdown()andup()). -
Granular Locking: Instead of locking the entire database, each seat has its own binary semaphore. This allows multiple clients to book different seats simultaneously without blocking each other.
-
Dynamic Resource Allocation: The server generates unique file keys
ftokon the fly to create ephemeral communication channels for each session.
This project includes a Makefile for automated build.
- GCC Compiler
- Linux Environment (supports System V IPC)
- Make
make-
Start the Server: The server initializes the shared memory map and semaphores.
./servidor
-
Start Client(s): Open a new terminal for each client. You can run multiple instances to test concurrency.
./cliente
Since System V IPC resources persist after process termination, use the clean command to remove semaphores and shared memory segments:
make clean(This triggers ipcrm commands defined in the Makefile).