Parallel File Copy Using Custom pread/pwrite with Multithreading

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-04-26

Problem Statement

Implement a high-performance file copy utility that copies a (possibly very large) file from source to destination using a thread pool and custom implementations of pread/pwrite semantics. Your copy must be correct, thread-safe, and measurably faster than a single-threaded baseline on multi-core systems.


Background

POSIX pread/pwrite perform offset-based I/O without changing the file offset and are naturally thread-safe. Some environments or wrappers may lack them, or you may want to instrument them. You will:

1.<span></span>build your own my_pread/my_pwrite that provide identical semantics (atomic w.r.t. file offset, retry on partial I/O, EINTR, etc.), and
2.<span></span>use them in a multithreaded copier that splits the file into chunks and processes chunks in parallel.



Solution

Comments