I'm reading in multuple tiny files and outputing them in a single file that is 5 seconds long. I can't control when the input files come in, how large they are, length of time contained inside of each etc. I want to output a full file every 5 seconds with all the data in every file generated for that 5 second interval. I want this to act in a quasi-streaming manner, no buffering files and creating output 5 seconds in the future.
This in a situation like this I have to handle the case when no input file exists by sleeping and waking up to pole for new values. However, I also need to stop my sleep/polling when I hit the 5 second mark so I output my new 5 second block. Which implies I have to be doing some comparisons to a clock to know if 5 seconds have passed and I'm ready to output my results.
I'm wondering if each of these wall clock checks will become system calls to the OS with all the expense tht entails? If possible, without too much effort, I would prefer to minimize CPU calls to get the wall clock (mainly to save CPU, I'll be doing very quick polling and the constant CPU calls for each of dozens of applications may actually burn up some CPU). What I would prefer is a system that works off of cpu cycles and only does a call to the OS on occasion to re-sync it's internal timer. Now for this program it's not worth going out of my way to implement anything complicated, but it made me wonder. Does the c++ language already mave any methods that do what I described, working with cpu time and syncing to wall clock intermittently, or do they always do a system call every time I try to get time?
Thanks