There is no reason to use threads for this. Open both files, read from one file, compute your sum, and write it to the second file. When the reading file is at the end, close both files.