For the sake of an exercise, say you have an input file with a series of lines of text with the objective of reversing their respective character sequences.
Now introduce 5 threads that will each do the reversing, thread 1 taking care of line 1, thread 2 taking care of line 2 and so on.
If the aim is to save these reversed lines in order, how would you save them to the same file ?
P.S: I've thought of having some kind of queue but there is no guarantee on the order. Also, I'm wondering if there's some way to lock the file temporarily and have a thread wait it's turn. I imagine I should keep track of which line is being saved.