Just some improvement suggestions to an otherwise excellent method:
- The use of volatile decalaration for the loop guard will make the loop much more terse.
- Sticking in an odd call to sleep(1); will make your instrumented system much easier on your the rest of your OS.
Cheers,
---Lars