How sara-l-s-silva/concorrencia-so works
Project type and purpose
• This is a command-line, multithreaded sorting tool written in C for a university assignment.
• It reads a file of records, sorts them (by key only) using a user-specified or automatic number of threads, then writes and fsync/msync’s the output file.
File structure
• There is a single source file (psort14677190.c) under “Código/”.
• A PDF under “Instruções/” describes requirements.
• The README explains usage, threading requirements, and performance analysis.
• No frontend/backend split—this is a standalone CLI tool with one major binary.
README for insights
• Inputs: command-line arguments (<entrada>, <saída>, <threads>)
• Output: sorted file, forced to disk via fsync() or msync()
• Runtime: spawns up to N worker threads or decides N itself, performs sorting, merges results
Main components
a. CLI Parser
b. File I/O subsystem
• Input File Reader
• Output File Writer (with fsync/msync)
c. In-memory Record Buffer or Array
d. Thread Pool / Thread Manager
e. Worker Threads (each executes sort on a chunk)
f. Merge Module (combines sorted subarrays)
g. Synchronization Primitives (mutexes, barriers)
h. Operating System / File System (external service)
Relationships & data flow
• User invokes the executable → CLI Parser interprets arguments
• CLI Parser → Input File Reader loads records into memory buffer
• Thread Manager divides the buffer into chunks and spawns Worker Threads
• Worker Threads independently sort their assigned chunk (use qsort or custom)
• Upon completion, Worker Threads synchronize at a barrier → Merge Module runs in main thread
• Merge Module writes the combined sorted array → Output File Writer → OS/File System → disk
• Before exit, Output File Writer calls fsync()/msync() to flush data to disk
Architectural patterns & design principles
• Divide-and-conquer (split array into N parts)
• Thread-pool or dynamic thread allocation based on <threads> parameter
• -reduce style: map = sort chunks in parallel, reduce = merge sorted chunks
• Explicit synchronization to prevent race conditions (mutexes or barriers)
• Clear separation between computation (sorting) and I/O
• Clear, human-readable labels on each component
• Arrowheads that indicate the direction of data and control flow
• Callouts for critical operations (e.g., “spawn up to <threads> workers,” “fsync()”)