June 23rd, 2013, 08:13 PM
Monitoring progress of a subroutine that is using a file stream as an input
What is the traditional way to monitor a blocking subroutine that is using a file stream as its input? That is, what is the traditional way to make a progress meter in the console?
Say I have a function that takes in a filestream and works with it. Suppose this file stream has a position and length property like in C# FileStream:
Presumably the function is chomping along the file stream as it is doing some calculations serially on the file stream.
void sub (filestream file)
//read a bit of the stream, which advances stream cursor position
//repeat until all of file stream has been used up
Because the function is blocking, there is no way to access the file streams position and length in this thread. So naturally it seems like the best thing to do to monitor the progress of that function is to make another thread and pass it the file stream object as a parameter, and in this separate thread, monitor the distance between filestream's position and length to determine how much of the file stream has been used up, and every second or so output the amount of file stream used onto the console.
Is this how things are traditionally done?
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!