简体   繁体   中英

Multithread file copy to different hard drive using c++

I need to develop an application that can copy faster than OS copy using 1 thread to read source files and another thread to write them. Source and target files are located in different hard drive.

My question is how to pass the result of source read thread into target write thread without resulting some race condition and still maintain top performance of the copy process to achieve faster copy process than OS copy.

Use a bounded queue.
You can use any queue ( TBB , std::deque, cirtular buffer , whatever). If it isn't thread-safe and/or blocking then synchronize around it and use conditional variables for notification. You don't need smart tricks in the queue because passing a pointer to a chunk of data into the queue is much faster then the I/O, but if you really want to over-optimize then check the disruptor (described here ).

To reviewers: Note that the question is about copying between different hard-drives, so a multithreaded copy will benefit it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM