How saitejkuralla/semaphore works
Project Type and Purpose
• Type: A multi-module console application suite (C#/.NET) illustrating thread synchronization patterns.
• Purpose: Provide real-world examples of Lock, Monitor, Semaphore, and SemaphoreSlim in isolated scenarios (BusReservation, SharedBankAccount, AtmAccess, LimitingCreditCard, LimitingServices).
File Structure
• Top-level solution: Multi threading.sln
• Five subprojects (each a console app with its own .csproj and Program.cs):
• BusReservationSystem
• SharedBankAccount
• AtmAccess
• LimitingCreditCard
• LimitingServices
• Each project lives in its own folder and references System.Threading primitives.
README for Insights
• Describes which synchronization primitive is exercised in each project.
• Documents the high-level workflow of threads, shared resources, and signaling/waiting.
Main Components & Interactions
a. Solution Container
• Represents the Visual Studio solution that groups the five demo modules.
b. Module (one per folder)
• Console App Host
• Thread Manager (creates/starts threads)
• Shared Resource (e.g., AvailableTickets, BankAccount.Balance, ATM machines, CreditCard queue, Service endpoints)
• Synchronization Primitive (Lock object, Monitor, Semaphore, SemaphoreSlim)
c. Threads
• Worker threads performing actions on the shared resource.
d. .NET Runtime
• Thread Scheduler, CLR, Threading Library (System.Threading namespace).
Interactions:
• Threads → request access via Sync Primitive → operate on Shared Resource → release Sync Primitive → continue.
Architectural Patterns & Principles
• Mutual Exclusion (Lock, Monitor.Enter/Exit)
• Counting Semaphore (Semaphore, SemaphoreSlim)
• Producer-Consumer / Signaling (Monitor.Wait/Pulse)
• Separation of concerns: each module is self-contained; no cross-module dependencies.